From 184b0a1a527482264bdb59a79f03db88c294c645 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 21 Sep 2023 00:32:39 +1000 Subject: [PATCH] Misc: Swap most C format strings for fmt --- src/common/file_system.cpp | 37 ++++++++--------- src/core/achievements.cpp | 13 +++--- src/core/gdb_protocol.cpp | 3 +- src/core/gpu_commands.cpp | 9 ++-- src/core/imgui_overlays.cpp | 3 +- src/core/system.cpp | 9 ++-- src/duckstation-qt/cheatmanagerdialog.cpp | 4 +- .../memorycardsettingswidget.cpp | 2 +- src/util/cd_image_hasher.cpp | 25 +++++------ src/util/cd_image_pbp.cpp | 2 +- src/util/cubeb_audio_stream.cpp | 5 ++- src/util/d3d11_device.cpp | 2 +- src/util/d3d12_device.cpp | 2 +- src/util/gpu_device.cpp | 2 +- src/util/imgui_fullscreen.cpp | 17 ++++---- src/util/input_source.cpp | 8 ++-- src/util/sdl_input_source.cpp | 41 +++++++++---------- src/util/vulkan_device.cpp | 12 +++--- src/util/xinput_source.cpp | 27 ++++++------ 19 files changed, 107 insertions(+), 116 deletions(-) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 3a8bc73c0..b344a5882 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -915,13 +915,13 @@ static u32 RecursiveFindFiles(const char* origin_path, const char* parent_path, if (path) { if (parent_path) - tempStr = StringUtil::StdStringFromFormat("%s\\%s\\%s\\*", origin_path, parent_path, path); + tempStr = fmt::format("{}\\{}\\{}\\*", origin_path, parent_path, path); else - tempStr = StringUtil::StdStringFromFormat("%s\\%s\\*", origin_path, path); + tempStr = fmt::format("{}\\{}\\*", origin_path, path); } else { - tempStr = StringUtil::StdStringFromFormat("%s\\*", origin_path); + tempStr = fmt::format("{}\\*", origin_path); } // holder for utf-8 conversion @@ -969,7 +969,7 @@ static u32 RecursiveFindFiles(const char* origin_path, const char* parent_path, // recurse into this directory if (parent_path != nullptr) { - const std::string recurseDir = StringUtil::StdStringFromFormat("%s\\%s", parent_path, path); + const std::string recurseDir = fmt::format("{}\\{}", parent_path, path); nFiles += RecursiveFindFiles(origin_path, recurseDir.c_str(), utf8_filename.c_str(), pattern, flags, results); } else @@ -1009,19 +1009,18 @@ static u32 RecursiveFindFiles(const char* origin_path, const char* parent_path, if (!(flags & FILESYSTEM_FIND_RELATIVE_PATHS)) { if (parent_path != nullptr) - outData.FileName = - StringUtil::StdStringFromFormat("%s\\%s\\%s\\%s", origin_path, parent_path, path, utf8_filename.c_str()); + outData.FileName = fmt::format("{}\\{}\\{}\\{}", origin_path, parent_path, path, utf8_filename.c_str()); else if (path != nullptr) - outData.FileName = StringUtil::StdStringFromFormat("%s\\%s\\%s", origin_path, path, utf8_filename.c_str()); + outData.FileName = fmt::format("{}\\{}\\{}", origin_path, path, utf8_filename.c_str()); else - outData.FileName = StringUtil::StdStringFromFormat("%s\\%s", origin_path, utf8_filename.c_str()); + outData.FileName = fmt::format("{}\\{}", origin_path, utf8_filename.c_str()); } else { if (parent_path != nullptr) - outData.FileName = StringUtil::StdStringFromFormat("%s\\%s\\%s", parent_path, path, utf8_filename.c_str()); + outData.FileName = fmt::format("{}\\{}\\{}", parent_path, path, utf8_filename.c_str()); else if (path != nullptr) - outData.FileName = StringUtil::StdStringFromFormat("%s\\%s", path, utf8_filename.c_str()); + outData.FileName = fmt::format("{}\\{}", path, utf8_filename.c_str()); else outData.FileName = utf8_filename; } @@ -1447,13 +1446,13 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co if (Path) { if (ParentPath) - tempStr = StringUtil::StdStringFromFormat("%s/%s/%s", OriginPath, ParentPath, Path); + tempStr = fmt::format("{}/{}/{}", OriginPath, ParentPath, Path); else - tempStr = StringUtil::StdStringFromFormat("%s/%s", OriginPath, Path); + tempStr = fmt::format("{}/{}", OriginPath, Path); } else { - tempStr = StringUtil::StdStringFromFormat("%s", OriginPath); + tempStr = OriginPath; } DIR* pDir = opendir(tempStr.c_str()); @@ -1485,11 +1484,11 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co std::string full_path; if (ParentPath != nullptr) - full_path = StringUtil::StdStringFromFormat("%s/%s/%s/%s", OriginPath, ParentPath, Path, pDirEnt->d_name); + full_path = fmt::format("{}/{}/{}/{}", OriginPath, ParentPath, Path, pDirEnt->d_name); else if (Path != nullptr) - full_path = StringUtil::StdStringFromFormat("%s/%s/%s", OriginPath, Path, pDirEnt->d_name); + full_path = fmt::format("{}/{}/{}", OriginPath, Path, pDirEnt->d_name); else - full_path = StringUtil::StdStringFromFormat("%s/%s", OriginPath, pDirEnt->d_name); + full_path = fmt::format("{}/{}", OriginPath, pDirEnt->d_name); FILESYSTEM_FIND_DATA outData; outData.Attributes = 0; @@ -1512,7 +1511,7 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co // recurse into this directory if (ParentPath != nullptr) { - std::string recursiveDir = StringUtil::StdStringFromFormat("%s/%s", ParentPath, Path); + std::string recursiveDir = fmt::format("{}/{}", ParentPath, Path); nFiles += RecursiveFindFiles(OriginPath, recursiveDir.c_str(), pDirEnt->d_name, Pattern, Flags, pResults); } else @@ -1557,9 +1556,9 @@ static u32 RecursiveFindFiles(const char* OriginPath, const char* ParentPath, co else { if (ParentPath != nullptr) - outData.FileName = StringUtil::StdStringFromFormat("%s/%s/%s", ParentPath, Path, pDirEnt->d_name); + outData.FileName = fmt::format("{}/{}/{}", ParentPath, Path, pDirEnt->d_name); else if (Path != nullptr) - outData.FileName = StringUtil::StdStringFromFormat("%s/%s", Path, pDirEnt->d_name); + outData.FileName = fmt::format("{}/{}", Path, pDirEnt->d_name); else outData.FileName = pDirEnt->d_name; } diff --git a/src/core/achievements.cpp b/src/core/achievements.cpp index 46877b79b..b7b95ccc6 100644 --- a/src/core/achievements.cpp +++ b/src/core/achievements.cpp @@ -269,7 +269,7 @@ std::string Achievements::GetGameHash(CDImage* image) std::memcpy(&header, executable_data.data(), sizeof(header)); if (!BIOS::IsValidPSExeHeader(header, static_cast(executable_data.size()))) { - Log_ErrorPrintf("PS-EXE header is invalid in '%s' (%zu bytes)", executable_name.c_str(), executable_data.size()); + Log_ErrorFmt("PS-EXE header is invalid in '{}' ({} bytes)", executable_name, executable_data.size()); return {}; } @@ -286,12 +286,11 @@ std::string Achievements::GetGameHash(CDImage* image) u8 hash[16]; digest.Final(hash); - std::string hash_str(StringUtil::StdStringFromFormat( - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", hash[0], hash[1], hash[2], hash[3], hash[4], - hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15])); + const std::string hash_str = fmt::format( + "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", hash[0], hash[1], hash[2], hash[3], hash[4], + hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]); - Log_InfoPrintf("Hash for '%s' (%zu bytes, %u bytes hashed): %s", executable_name.c_str(), executable_data.size(), - hash_size, hash_str.c_str()); + Log_InfoFmt("Hash for '{}' ({} bytes, {} bytes hashed): {}", executable_name, executable_data.size(), hash_size, hash_str); return hash_str; } @@ -304,7 +303,7 @@ void Achievements::DownloadImage(std::string url, std::string cache_filename) if (!FileSystem::WriteBinaryFile(cache_filename.c_str(), data.data(), data.size())) { - Log_ErrorPrintf("Failed to write badge image to '%s'", cache_filename.c_str()); + Log_ErrorFmt("Failed to write badge image to '{}'", cache_filename); return; } diff --git a/src/core/gdb_protocol.cpp b/src/core/gdb_protocol.cpp index bb5a0b909..aca25ef2e 100644 --- a/src/core/gdb_protocol.cpp +++ b/src/core/gdb_protocol.cpp @@ -8,6 +8,7 @@ #include "system.h" #include "common/log.h" +#include "common/small_string.h" #include "common/string_util.h" #include @@ -65,7 +66,7 @@ static std::optional DeserializePacket(const std::string_view& static std::string SerializePacket(const std::string_view& in) { std::stringstream ss; - ss << '$' << in << '#' << StringUtil::StdStringFromFormat("%02x", ComputeChecksum(in)); + ss << '$' << in << '#' << TinyString::from_fmt("{:02x}", ComputeChecksum(in)); return ss.str(); } diff --git a/src/core/gpu_commands.cpp b/src/core/gpu_commands.cpp index 767f1f4d9..1f46049e0 100644 --- a/src/core/gpu_commands.cpp +++ b/src/core/gpu_commands.cpp @@ -511,9 +511,8 @@ void GPU::FinishVRAMWrite() { if (g_settings.debugging.dump_cpu_to_vram_copies) { - DumpVRAMToFile(StringUtil::StdStringFromFormat("cpu_to_vram_copy_%u.png", s_cpu_to_vram_dump_id++).c_str(), - m_vram_transfer.width, m_vram_transfer.height, sizeof(u16) * m_vram_transfer.width, - m_blit_buffer.data(), true); + DumpVRAMToFile(TinyString::from_fmt("cpu_to_vram_copy_{}.png", s_cpu_to_vram_dump_id++), m_vram_transfer.width, + m_vram_transfer.height, sizeof(u16) * m_vram_transfer.width, m_blit_buffer.data(), true); } if (g_settings.texture_replacements.ShouldDumpVRAMWrite(m_vram_transfer.width, m_vram_transfer.height)) @@ -580,8 +579,8 @@ bool GPU::HandleCopyRectangleVRAMToCPUCommand() if (g_settings.debugging.dump_vram_to_cpu_copies) { - DumpVRAMToFile(StringUtil::StdStringFromFormat("vram_to_cpu_copy_%u.png", s_vram_to_cpu_dump_id++).c_str(), - m_vram_transfer.width, m_vram_transfer.height, sizeof(u16) * VRAM_WIDTH, + DumpVRAMToFile(TinyString::from_fmt("vram_to_cpu_copy_{}.png", s_vram_to_cpu_dump_id++), m_vram_transfer.width, + m_vram_transfer.height, sizeof(u16) * VRAM_WIDTH, &m_vram_ptr[m_vram_transfer.y * VRAM_WIDTH + m_vram_transfer.x], true); } diff --git a/src/core/imgui_overlays.cpp b/src/core/imgui_overlays.cpp index 59698829f..dd7744a87 100644 --- a/src/core/imgui_overlays.cpp +++ b/src/core/imgui_overlays.cpp @@ -773,8 +773,7 @@ void SaveStateSelectorUI::RefreshHotkeyLegend() setting = setting.substr(slash_pos + 1); } - return StringUtil::StdStringFromFormat("%.*s - %.*s", static_cast(setting.size()), setting.data(), - static_cast(caption.size()), caption.data()); + return fmt::format("{} - {}", setting, caption); }; s_load_legend = format_legend_entry(Host::GetStringSettingValue("Hotkeys", "LoadSelectedSaveState"), diff --git a/src/core/system.cpp b/src/core/system.cpp index 09f2b3c71..916322f58 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -542,7 +542,7 @@ ConsoleRegion System::GetConsoleRegionForDiscRegion(DiscRegion region) std::string System::GetGameHashId(GameHash hash) { - return StringUtil::StdStringFromFormat("HASH-%" PRIX64, hash); + return fmt::format("HASH-{:X}", hash); } bool System::GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash* out_hash) @@ -4255,10 +4255,9 @@ std::optional System::InternalGetExtendedSaveStateInfo(By ExtendedSaveStateInfo ssi; if (header.version < SAVE_STATE_MINIMUM_VERSION || header.version > SAVE_STATE_VERSION) { - ssi.title = StringUtil::StdStringFromFormat( - TRANSLATE("CommonHostInterface", "Invalid version %u (%s version %u)"), header.version, - header.version > SAVE_STATE_VERSION ? "maximum" : "minimum", - header.version > SAVE_STATE_VERSION ? SAVE_STATE_VERSION : SAVE_STATE_MINIMUM_VERSION); + ssi.title = fmt::format(TRANSLATE_FS("System", "Invalid version {} ({} version {})"), header.version, + header.version > SAVE_STATE_VERSION ? "maximum" : "minimum", + header.version > SAVE_STATE_VERSION ? SAVE_STATE_VERSION : SAVE_STATE_MINIMUM_VERSION); return ssi; } diff --git a/src/duckstation-qt/cheatmanagerdialog.cpp b/src/duckstation-qt/cheatmanagerdialog.cpp index 584c01447..61c2abc56 100644 --- a/src/duckstation-qt/cheatmanagerdialog.cpp +++ b/src/duckstation-qt/cheatmanagerdialog.cpp @@ -748,7 +748,7 @@ void CheatManagerDialog::addToWatchClicked() for (int index = indexFirst; index <= indexLast; index++) { const MemoryScan::Result& res = m_scanner.GetResults()[static_cast(index)]; - m_watch.AddEntry(StringUtil::StdStringFromFormat("0x%08x", res.address), res.address, m_scanner.GetSize(), + m_watch.AddEntry(fmt::format("0x{:08x}", res.address), res.address, m_scanner.GetSize(), m_scanner.GetValueSigned(), false); updateWatch(); } @@ -775,7 +775,7 @@ void CheatManagerDialog::addManualWatchAddressClicked() else if (index == 2 || index == 5) address.value() &= 0xFFFFFFFC; - m_watch.AddEntry(StringUtil::StdStringFromFormat("0x%08x", address.value()), address.value(), + m_watch.AddEntry(fmt::format("0x{:08x}", address.value()), address.value(), static_cast(index % 3), (index > 3), false); updateWatch(); } diff --git a/src/duckstation-qt/memorycardsettingswidget.cpp b/src/duckstation-qt/memorycardsettingswidget.cpp index bddd675e3..af4057ec7 100644 --- a/src/duckstation-qt/memorycardsettingswidget.cpp +++ b/src/duckstation-qt/memorycardsettingswidget.cpp @@ -127,7 +127,7 @@ void MemoryCardSettingsWidget::createPortSettingsUi(SettingsDialog* dialog, int const MemoryCardType default_value = (index == 0) ? MemoryCardType::PerGameTitle : MemoryCardType::None; SettingWidgetBinder::BindWidgetToEnumSetting(m_dialog->getSettingsInterface(), ui->memory_card_type, "MemoryCards", - StringUtil::StdStringFromFormat("Card%dType", index + 1), + fmt::format("Card{}Type", index + 1), &Settings::ParseMemoryCardTypeName, &Settings::GetMemoryCardTypeName, default_value); ui->layout->addWidget(new QLabel(tr("Memory Card Type:"), ui->container)); diff --git a/src/util/cd_image_hasher.cpp b/src/util/cd_image_hasher.cpp index f18164aea..73ac491e4 100644 --- a/src/util/cd_image_hasher.cpp +++ b/src/util/cd_image_hasher.cpp @@ -80,20 +80,21 @@ static bool ReadTrack(CDImage* image, u8 track, MD5Digest* digest, ProgressCallb std::string HashToString(const Hash& hash) { - return StringUtil::StdStringFromFormat("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", hash[0], - hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], hash[8], - hash[9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]); + return fmt::format("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", + hash[0], hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7], hash[8], hash[9], hash[10], + hash[11], hash[12], hash[13], hash[14], hash[15]); } -std::optional HashFromString(const std::string_view& str) { - auto decoded = StringUtil::DecodeHex(str); - if (decoded && decoded->size() == std::tuple_size_v) - { - Hash result; - std::copy(decoded->begin(), decoded->end(), result.begin()); - return result; - } - return std::nullopt; +std::optional HashFromString(const std::string_view& str) +{ + auto decoded = StringUtil::DecodeHex(str); + if (decoded && decoded->size() == std::tuple_size_v) + { + Hash result; + std::copy(decoded->begin(), decoded->end(), result.begin()); + return result; + } + return std::nullopt; } bool GetImageHash(CDImage* image, Hash* out_hash, diff --git a/src/util/cd_image_pbp.cpp b/src/util/cd_image_pbp.cpp index 4dcfe5e49..11d287a99 100644 --- a/src/util/cd_image_pbp.cpp +++ b/src/util/cd_image_pbp.cpp @@ -876,7 +876,7 @@ std::string CDImagePBP::GetSubImageMetadata(u32 index, const std::string_view& t { const std::string* title = LookupStringSFOTableEntry("TITLE", m_sfo_table); if (title && !title->empty()) - return StringUtil::StdStringFromFormat("%s (Disc %u)", title->c_str(), index + 1); + return fmt::format("{} (Disc {})", *title, index + 1); } return CDImage::GetSubImageMetadata(index, type); diff --git a/src/util/cubeb_audio_stream.cpp b/src/util/cubeb_audio_stream.cpp index 6a3de873f..f5fc8a933 100644 --- a/src/util/cubeb_audio_stream.cpp +++ b/src/util/cubeb_audio_stream.cpp @@ -36,11 +36,12 @@ CubebAudioStream::~CubebAudioStream() void CubebAudioStream::LogCallback(const char* fmt, ...) { + LargeString str; std::va_list ap; va_start(ap, fmt); - std::string msg(StringUtil::StdStringFromFormatV(fmt, ap)); + str.format_va(fmt, ap); va_end(ap); - Log_DevPrintf("(Cubeb): %s", msg.c_str()); + Log_DevPrint(str); } void CubebAudioStream::DestroyContextAndStream() diff --git a/src/util/d3d11_device.cpp b/src/util/d3d11_device.cpp index c096b1643..1d0e6e089 100644 --- a/src/util/d3d11_device.cpp +++ b/src/util/d3d11_device.cpp @@ -423,7 +423,7 @@ std::string D3D11Device::GetDriverInfo() const DXGI_ADAPTER_DESC desc; if (SUCCEEDED(dxgi_adapter->GetDesc(&desc))) { - ret += StringUtil::StdStringFromFormat("VID: 0x%04X PID: 0x%04X\n", desc.VendorId, desc.DeviceId); + fmt::format_to(std::back_inserter(ret), "VID: 0x{:04X} PID: 0x{:04X}\n", desc.VendorId, desc.DeviceId); ret += StringUtil::WideStringToUTF8String(desc.Description); ret += "\n"; diff --git a/src/util/d3d12_device.cpp b/src/util/d3d12_device.cpp index b940161f5..e165687b8 100644 --- a/src/util/d3d12_device.cpp +++ b/src/util/d3d12_device.cpp @@ -1039,7 +1039,7 @@ std::string D3D12Device::GetDriverInfo() const DXGI_ADAPTER_DESC desc; if (m_adapter && SUCCEEDED(m_adapter->GetDesc(&desc))) { - ret += StringUtil::StdStringFromFormat("VID: 0x%04X PID: 0x%04X\n", desc.VendorId, desc.DeviceId); + fmt::format_to(std::back_inserter(ret), "VID: 0x{:04X} PID: 0x{:04X}\n", desc.VendorId, desc.DeviceId); ret += StringUtil::WideStringToUTF8String(desc.Description); ret += "\n"; diff --git a/src/util/gpu_device.cpp b/src/util/gpu_device.cpp index 38e64451a..d14abb1e3 100644 --- a/src/util/gpu_device.cpp +++ b/src/util/gpu_device.cpp @@ -635,7 +635,7 @@ bool GPUDevice::GetRequestedExclusiveFullscreenMode(u32* width, u32* height, flo std::string GPUDevice::GetFullscreenModeString(u32 width, u32 height, float refresh_rate) { - return StringUtil::StdStringFromFormat("%u x %u @ %f hz", width, height, refresh_rate); + return fmt::format("{} x {} @ {} hz", width, height, refresh_rate); } std::string GPUDevice::GetShaderDumpPath(const std::string_view& name) diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index f0e57fcac..e63610295 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -1691,10 +1691,7 @@ void ImGuiFullscreen::PopulateFileSelectorItems() if (s_file_selector_current_directory.empty()) { for (std::string& root_path : FileSystem::GetRootDirectoryList()) - { - s_file_selector_items.emplace_back(StringUtil::StdStringFromFormat(ICON_FA_FOLDER " %s", root_path.c_str()), - std::move(root_path), false); - } + s_file_selector_items.emplace_back(fmt::format(ICON_FA_FOLDER " {}", root_path), std::move(root_path), false); } else { @@ -1722,12 +1719,12 @@ void ImGuiFullscreen::PopulateFileSelectorItems() for (const FILESYSTEM_FIND_DATA& fd : results) { - std::string full_path(StringUtil::StdStringFromFormat( - "%s" FS_OSPATH_SEPARATOR_STR "%s", s_file_selector_current_directory.c_str(), fd.FileName.c_str())); + std::string full_path = + fmt::format("{}" FS_OSPATH_SEPARATOR_STR "{}", s_file_selector_current_directory, fd.FileName); if (fd.Attributes & FILESYSTEM_FILE_ATTRIBUTE_DIRECTORY) { - std::string title(StringUtil::StdStringFromFormat(ICON_FA_FOLDER " %s", fd.FileName.c_str())); + std::string title = fmt::format(ICON_FA_FOLDER " {}", fd.FileName); s_file_selector_items.emplace_back(std::move(title), std::move(full_path), false); } else @@ -1741,7 +1738,7 @@ void ImGuiFullscreen::PopulateFileSelectorItems() continue; } - std::string title(StringUtil::StdStringFromFormat(ICON_FA_FILE " %s", fd.FileName.c_str())); + std::string title = fmt::format(ICON_FA_FILE " {}", fd.FileName); s_file_selector_items.emplace_back(std::move(title), std::move(full_path), true); } } @@ -1770,7 +1767,7 @@ void ImGuiFullscreen::OpenFileSelector(const char* title, bool select_directory, s_file_selector_open = true; s_file_selector_directory = select_directory; - s_file_selector_title = StringUtil::StdStringFromFormat("%s##file_selector", title); + s_file_selector_title = fmt::format("{}##file_selector", title); s_file_selector_callback = std::move(callback); s_file_selector_filters = std::move(filters); @@ -1894,7 +1891,7 @@ void ImGuiFullscreen::OpenChoiceDialog(const char* title, bool checkable, Choice s_choice_dialog_open = true; s_choice_dialog_checkable = checkable; - s_choice_dialog_title = StringUtil::StdStringFromFormat("%s##choice_dialog", title); + s_choice_dialog_title = fmt::format("{}##choice_dialog", title); s_choice_dialog_options = std::move(options); s_choice_dialog_callback = std::move(callback); } diff --git a/src/util/input_source.cpp b/src/util/input_source.cpp index c89b7a91e..6165b35d3 100644 --- a/src/util/input_source.cpp +++ b/src/util/input_source.cpp @@ -141,13 +141,13 @@ std::string InputSource::ConvertGenericControllerKeyToString(InputBindingKey key modifier = "Full"; break; } - return StringUtil::StdStringFromFormat("%s-%u/%sAxis%u", InputManager::InputSourceToString(key.source_type), - key.source_index, modifier, key.data); + return fmt::format("{}-{}/{}Axis{}", InputManager::InputSourceToString(key.source_type), + static_cast(key.source_index), modifier, key.data); } else if (key.source_subtype == InputSubclass::ControllerButton) { - return StringUtil::StdStringFromFormat("%s%u/Button%u", InputManager::InputSourceToString(key.source_type), - key.source_index, key.data); + return fmt::format("{}{}/Button{}", InputManager::InputSourceToString(key.source_type), + static_cast(key.source_index), key.data); } else { diff --git a/src/util/sdl_input_source.cpp b/src/util/sdl_input_source.cpp index 6ce5c170f..ecafd5de5 100644 --- a/src/util/sdl_input_source.cpp +++ b/src/util/sdl_input_source.cpp @@ -261,7 +261,7 @@ std::vector> SDLInputSource::EnumerateDevice for (const ControllerData& cd : m_controllers) { - std::string id(StringUtil::StdStringFromFormat("SDL-%d", cd.player_id)); + std::string id = fmt::format("SDL-{}", cd.player_id); const char* name = cd.game_controller ? SDL_GameControllerName(cd.game_controller) : SDL_JoystickName(cd.joystick); if (name) @@ -407,41 +407,40 @@ std::string SDLInputSource::ConvertKeyToString(InputBindingKey key) (key.modifier == InputModifier::FullAxis ? "Full" : (key.modifier == InputModifier::Negate ? "-" : "+")); if (key.data < std::size(s_sdl_axis_names)) { - ret = StringUtil::StdStringFromFormat("SDL-%u/%s%s", key.source_index, modifier, s_sdl_axis_names[key.data]); + ret = fmt::format("SDL-{}/{}{}", static_cast(key.source_index), modifier, s_sdl_axis_names[key.data]); } else { - ret = StringUtil::StdStringFromFormat("SDL-%u/%sAxis%u%s", key.source_index, modifier, - key.data - static_cast(std::size(s_sdl_axis_names)), - key.invert ? "~" : ""); + ret = fmt::format("SDL-{}/{}Axis{}{}", static_cast(key.source_index), modifier, + key.data - static_cast(std::size(s_sdl_axis_names)), key.invert ? "~" : ""); } } else if (key.source_subtype == InputSubclass::ControllerButton) { if (key.data < std::size(s_sdl_button_names)) { - ret = StringUtil::StdStringFromFormat("SDL-%u/%s", key.source_index, s_sdl_button_names[key.data]); + ret = fmt::format("SDL-{}/{}", static_cast(key.source_index), s_sdl_button_names[key.data]); } else { - ret = StringUtil::StdStringFromFormat("SDL-%u/Button%u", key.source_index, - key.data - static_cast(std::size(s_sdl_button_names))); + ret = fmt::format("SDL-{}/Button{}", static_cast(key.source_index), + key.data - static_cast(std::size(s_sdl_button_names))); } } else if (key.source_subtype == InputSubclass::ControllerHat) { const u32 hat_index = key.data / static_cast(std::size(s_sdl_hat_direction_names)); const u32 hat_direction = key.data % static_cast(std::size(s_sdl_hat_direction_names)); - ret = StringUtil::StdStringFromFormat("SDL-%u/Hat%u%s", key.source_index, hat_index, - s_sdl_hat_direction_names[hat_direction]); + ret = fmt::format("SDL-{}/Hat{}{}", static_cast(key.source_index), hat_index, + s_sdl_hat_direction_names[hat_direction]); } else if (key.source_subtype == InputSubclass::ControllerMotor) { - ret = StringUtil::StdStringFromFormat("SDL-%u/%sMotor", key.source_index, key.data ? "Large" : "Small"); + ret = fmt::format("SDL-{}/{}Motor", static_cast(key.source_index), key.data ? "Large" : "Small"); } else if (key.source_subtype == InputSubclass::ControllerHaptic) { - ret = StringUtil::StdStringFromFormat("SDL-%u/Haptic", key.source_index); + ret = fmt::format("SDL-{}/Haptic", static_cast(key.source_index)); } } @@ -681,7 +680,7 @@ bool SDLInputSource::OpenDevice(int index, bool is_gamecontroller) m_controllers.push_back(std::move(cd)); - InputManager::OnInputDeviceConnected(StringUtil::StdStringFromFormat("SDL-%d", player_id), name); + InputManager::OnInputDeviceConnected(fmt::format("SDL-{}", player_id), name); return true; } @@ -691,7 +690,7 @@ bool SDLInputSource::CloseDevice(int joystick_index) if (it == m_controllers.end()) return false; - InputManager::OnInputDeviceDisconnected(StringUtil::StdStringFromFormat("SDL-%d", it->player_id)); + InputManager::OnInputDeviceDisconnected(fmt::format("SDL-{}", it->player_id)); if (it->haptic) SDL_HapticClose(it->haptic); @@ -842,27 +841,27 @@ bool SDLInputSource::GetGenericBindingMapping(const std::string_view& device, Ge const GenericInputBinding negative = s_sdl_generic_binding_axis_mapping[i][0]; const GenericInputBinding positive = s_sdl_generic_binding_axis_mapping[i][1]; if (negative != GenericInputBinding::Unknown) - mapping->emplace_back(negative, StringUtil::StdStringFromFormat("SDL-%d/-%s", pid, s_sdl_axis_names[i])); + mapping->emplace_back(negative, fmt::format("SDL-{}/-{}", pid, s_sdl_axis_names[i])); if (positive != GenericInputBinding::Unknown) - mapping->emplace_back(positive, StringUtil::StdStringFromFormat("SDL-%d/+%s", pid, s_sdl_axis_names[i])); + mapping->emplace_back(positive, fmt::format("SDL-{}/+{}", pid, s_sdl_axis_names[i])); } for (u32 i = 0; i < std::size(s_sdl_generic_binding_button_mapping); i++) { const GenericInputBinding binding = s_sdl_generic_binding_button_mapping[i]; if (binding != GenericInputBinding::Unknown) - mapping->emplace_back(binding, StringUtil::StdStringFromFormat("SDL-%d/%s", pid, s_sdl_button_names[i])); + mapping->emplace_back(binding, fmt::format("SDL-{}/{}", pid, s_sdl_button_names[i])); } if (it->use_game_controller_rumble || it->haptic_left_right_effect) { - mapping->emplace_back(GenericInputBinding::SmallMotor, StringUtil::StdStringFromFormat("SDL-%d/SmallMotor", pid)); - mapping->emplace_back(GenericInputBinding::LargeMotor, StringUtil::StdStringFromFormat("SDL-%d/LargeMotor", pid)); + mapping->emplace_back(GenericInputBinding::SmallMotor, fmt::format("SDL-{}/SmallMotor", pid)); + mapping->emplace_back(GenericInputBinding::LargeMotor, fmt::format("SDL-{}/LargeMotor", pid)); } else { - mapping->emplace_back(GenericInputBinding::SmallMotor, StringUtil::StdStringFromFormat("SDL-%d/Haptic", pid)); - mapping->emplace_back(GenericInputBinding::LargeMotor, StringUtil::StdStringFromFormat("SDL-%d/Haptic", pid)); + mapping->emplace_back(GenericInputBinding::SmallMotor, fmt::format("SDL-{}/Haptic", pid)); + mapping->emplace_back(GenericInputBinding::LargeMotor, fmt::format("SDL-{}/Haptic", pid)); } return true; diff --git a/src/util/vulkan_device.cpp b/src/util/vulkan_device.cpp index 4caad3edf..bc5a74a1c 100644 --- a/src/util/vulkan_device.cpp +++ b/src/util/vulkan_device.cpp @@ -1982,8 +1982,8 @@ std::string VulkanDevice::GetDriverInfo() const if (m_optional_extensions.vk_khr_driver_properties) { const VkPhysicalDeviceDriverProperties& props = m_device_driver_properties; - ret = StringUtil::StdStringFromFormat( - "Driver %u.%u.%u\nVulkan %u.%u.%u\nConformance Version %u.%u.%u.%u\n%s\n%s\n%s", VK_VERSION_MAJOR(driver_version), + ret = fmt::format( + "Driver {}.{}.{}\nVulkan {}.{}.{}\nConformance Version {}.{}.{}.{}\n{}\n{}\n{}", VK_VERSION_MAJOR(driver_version), VK_VERSION_MINOR(driver_version), VK_VERSION_PATCH(driver_version), VK_API_VERSION_MAJOR(api_version), VK_API_VERSION_MINOR(api_version), VK_API_VERSION_PATCH(api_version), props.conformanceVersion.major, props.conformanceVersion.minor, props.conformanceVersion.subminor, props.conformanceVersion.patch, @@ -1991,10 +1991,10 @@ std::string VulkanDevice::GetDriverInfo() const } else { - ret = StringUtil::StdStringFromFormat("Driver %u.%u.%u\nVulkan %u.%u.%u\n%s", VK_VERSION_MAJOR(driver_version), - VK_VERSION_MINOR(driver_version), VK_VERSION_PATCH(driver_version), - VK_API_VERSION_MAJOR(api_version), VK_API_VERSION_MINOR(api_version), - VK_API_VERSION_PATCH(api_version), m_device_properties.deviceName); + ret = + fmt::format("Driver {}.{}.{}\nVulkan {}.{}.{}\n{}", VK_VERSION_MAJOR(driver_version), + VK_VERSION_MINOR(driver_version), VK_VERSION_PATCH(driver_version), VK_API_VERSION_MAJOR(api_version), + VK_API_VERSION_MINOR(api_version), VK_API_VERSION_PATCH(api_version), m_device_properties.deviceName); } return ret; diff --git a/src/util/xinput_source.cpp b/src/util/xinput_source.cpp index ed2312c2a..36f351674 100644 --- a/src/util/xinput_source.cpp +++ b/src/util/xinput_source.cpp @@ -215,8 +215,7 @@ std::vector> XInputSource::EnumerateDevices( if (!m_controllers[i].connected) continue; - ret.emplace_back(StringUtil::StdStringFromFormat("XInput-%u", i), - StringUtil::StdStringFromFormat("XInput Controller %u", i)); + ret.emplace_back(fmt::format("XInput-{}", i), fmt::format("XInput Controller {}", i)); } return ret; @@ -297,15 +296,15 @@ std::string XInputSource::ConvertKeyToString(InputBindingKey key) if (key.source_subtype == InputSubclass::ControllerAxis && key.data < std::size(s_axis_names)) { const char modifier = key.modifier == InputModifier::Negate ? '-' : '+'; - ret = StringUtil::StdStringFromFormat("XInput-%u/%c%s", key.source_index, modifier, s_axis_names[key.data]); + ret = fmt::format("XInput-{}/{}{}", static_cast(key.source_index), modifier, s_axis_names[key.data]); } else if (key.source_subtype == InputSubclass::ControllerButton && key.data < std::size(s_button_names)) { - ret = StringUtil::StdStringFromFormat("XInput-%u/%s", key.source_index, s_button_names[key.data]); + ret = fmt::format("XInput-{}/{}", static_cast(key.source_index), s_button_names[key.data]); } else if (key.source_subtype == InputSubclass::ControllerMotor) { - ret = StringUtil::StdStringFromFormat("XInput-%u/%sMotor", key.source_index, key.data ? "Large" : "Small"); + ret = fmt::format("XInput-{}/{}Motor", static_cast(key.source_index), key.data ? "Large" : "Small"); } } @@ -351,24 +350,22 @@ bool XInputSource::GetGenericBindingMapping(const std::string_view& device, Gene const GenericInputBinding negative = s_xinput_generic_binding_axis_mapping[i][0]; const GenericInputBinding positive = s_xinput_generic_binding_axis_mapping[i][1]; if (negative != GenericInputBinding::Unknown) - mapping->emplace_back(negative, StringUtil::StdStringFromFormat("XInput-%d/-%s", pid, s_axis_names[i])); + mapping->emplace_back(negative, fmt::format("XInput-{}/-{}", pid, s_axis_names[i])); if (positive != GenericInputBinding::Unknown) - mapping->emplace_back(positive, StringUtil::StdStringFromFormat("XInput-%d/+%s", pid, s_axis_names[i])); + mapping->emplace_back(positive, fmt::format("XInput-{}/+{}", pid, s_axis_names[i])); } for (u32 i = 0; i < std::size(s_xinput_generic_binding_button_mapping); i++) { const GenericInputBinding binding = s_xinput_generic_binding_button_mapping[i]; if (binding != GenericInputBinding::Unknown) - mapping->emplace_back(binding, StringUtil::StdStringFromFormat("XInput-%d/%s", pid, s_button_names[i])); + mapping->emplace_back(binding, fmt::format("XInput-{}/{}", pid, s_button_names[i])); } if (m_controllers[pid].has_small_motor) - mapping->emplace_back(GenericInputBinding::SmallMotor, - StringUtil::StdStringFromFormat("XInput-%d/SmallMotor", pid)); + mapping->emplace_back(GenericInputBinding::SmallMotor, fmt::format("XInput-{}/SmallMotor", pid)); if (m_controllers[pid].has_large_motor) - mapping->emplace_back(GenericInputBinding::LargeMotor, - StringUtil::StdStringFromFormat("XInput-%d/LargeMotor", pid)); + mapping->emplace_back(GenericInputBinding::LargeMotor, fmt::format("XInput-{}/LargeMotor", pid)); return true; } @@ -387,14 +384,14 @@ void XInputSource::HandleControllerConnection(u32 index) cd.has_small_motor = caps.Vibration.wRightMotorSpeed != 0; cd.last_state = {}; - InputManager::OnInputDeviceConnected(StringUtil::StdStringFromFormat("XInput-%u", index), - StringUtil::StdStringFromFormat("XInput Controller %u", index)); + InputManager::OnInputDeviceConnected(fmt::format("XInput-{}", index), + fmt::format("XInput Controller {}", index)); } void XInputSource::HandleControllerDisconnection(u32 index) { Log_InfoPrintf("XInput controller %u disconnected.", index); - InputManager::OnInputDeviceDisconnected(StringUtil::StdStringFromFormat("XInput-%u", index)); + InputManager::OnInputDeviceDisconnected(fmt::format("XInput-{}", index)); m_controllers[index] = {}; }