Merge pull request #14738 from tygyh/Replace-concatination-with-stdformat

Replace string concatination with `fmt::format`
This commit is contained in:
Scott Mansell
2026-07-29 13:28:58 +12:00
committed by GitHub
12 changed files with 56 additions and 38 deletions
@@ -3,6 +3,8 @@
#include <android/log.h>
#include <fmt/format.h>
#include "Common/TraversalClient.h"
#include "Core/Boot/Boot.h"
#include "Core/Core.h"
@@ -34,7 +36,7 @@ std::string InetAddressToString(const Common::TraversalInetAddress& addr)
}
}
return ip + ":" + std::to_string(ntohs(addr.port));
return fmt::format("{}:{}", ip, ntohs(addr.port));
}
const char* FailureReasonToString(Common::TraversalClient::FailureReason reason)
+3 -1
View File
@@ -15,6 +15,8 @@
#include <thread>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/HRWrap.h"
#include "Common/Logging/Log.h"
@@ -110,7 +112,7 @@ static void ForEachNamedDevice(const std::function<bool(ComPtr<IMMDevice>, std::
{
ComPtr<IMMDevice> device;
devices->Item(i, &device);
if (!HandleWinAPI("Failed to get device " + std::to_string(i), result))
if (!HandleWinAPI(fmt::format("Failed to get device {}", i), result))
continue;
ComPtr<IPropertyStore> device_properties;
@@ -6,6 +6,8 @@
#include <algorithm>
#include <utility>
#include <fmt/format.h>
#include "Core/Config/MainSettings.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
@@ -81,7 +83,7 @@ private:
}
std::string GetCubebStreamName() const override
{
return "Dolphin Emulated Logitech USB Microphone " + std::to_string(m_index);
return fmt::format("Dolphin Emulated Logitech USB Microphone {}", m_index);
}
s16 GetVolumeModifier() const override
{
@@ -12,6 +12,8 @@
#include <QTableWidget>
#include <QVBoxLayout>
#include <fmt/format.h>
#include "Core/Core.h"
#include "Core/Debugger/CodeTrace.h"
#include "Core/HW/ProcessorInterface.h"
@@ -338,13 +340,13 @@ void RegisterWidget::PopulateTable()
{
// General purpose registers (int)
AddRegister(
i, 0, RegisterType::gpr, "r" + std::to_string(i),
i, 0, RegisterType::gpr, fmt::format("r{}", i),
[this, i] { return m_system.GetPPCState().gpr[i]; },
[this, i](u64 value) { m_system.GetPPCState().gpr[i] = value; });
// Floating point registers (double)
AddRegister(
i, 2, RegisterType::fpr, "f" + std::to_string(i),
i, 2, RegisterType::fpr, fmt::format("f{}", i),
[this, i] { return m_system.GetPPCState().ps[i].PS0AsU64(); },
[this, i](u64 value) { m_system.GetPPCState().ps[i].SetPS0(value); });
@@ -360,7 +362,7 @@ void RegisterWidget::PopulateTable()
{
// IBAT registers
AddRegister(
i, 5, RegisterType::ibat, "IBAT" + std::to_string(i),
i, 5, RegisterType::ibat, fmt::format("IBAT{}", i),
[this, i] {
const auto& ppc_state = m_system.GetPPCState();
return (static_cast<u64>(ppc_state.spr[SPR_IBAT0U + i * 2]) << 32) +
@@ -368,7 +370,7 @@ void RegisterWidget::PopulateTable()
},
nullptr);
AddRegister(
i + 4, 5, RegisterType::ibat, "IBAT" + std::to_string(4 + i),
i + 4, 5, RegisterType::ibat, fmt::format("IBAT{}", 4 + i),
[this, i] {
const auto& ppc_state = m_system.GetPPCState();
return (static_cast<u64>(ppc_state.spr[SPR_IBAT4U + i * 2]) << 32) +
@@ -378,7 +380,7 @@ void RegisterWidget::PopulateTable()
// DBAT registers
AddRegister(
i + 8, 5, RegisterType::dbat, "DBAT" + std::to_string(i),
i + 8, 5, RegisterType::dbat, fmt::format("DBAT{}", i),
[this, i] {
const auto& ppc_state = m_system.GetPPCState();
return (static_cast<u64>(ppc_state.spr[SPR_DBAT0U + i * 2]) << 32) +
@@ -386,7 +388,7 @@ void RegisterWidget::PopulateTable()
},
nullptr);
AddRegister(
i + 12, 5, RegisterType::dbat, "DBAT" + std::to_string(4 + i),
i + 12, 5, RegisterType::dbat, fmt::format("DBAT{}", 4 + i),
[this, i] {
const auto& ppc_state = m_system.GetPPCState();
return (static_cast<u64>(ppc_state.spr[SPR_DBAT4U + i * 2]) << 32) +
@@ -399,7 +401,7 @@ void RegisterWidget::PopulateTable()
{
// Graphics quantization registers
AddRegister(
i + 16, 7, RegisterType::gqr, "GQR" + std::to_string(i),
i + 16, 7, RegisterType::gqr, fmt::format("GQR{}", i),
[this, i] { return m_system.GetPPCState().spr[SPR_GQR0 + i]; }, nullptr);
}
@@ -421,7 +423,7 @@ void RegisterWidget::PopulateTable()
{
// SR registers
AddRegister(
i, 7, RegisterType::sr, "SR" + std::to_string(i),
i, 7, RegisterType::sr, fmt::format("SR{}", i),
[this, i] { return m_system.GetPPCState().sr[i]; },
[this, i](u64 value) {
m_system.GetPPCState().sr[i] = value;
+1 -1
View File
@@ -344,7 +344,7 @@ void HotkeyScheduler::Run()
OSD::AddMessage(std::string("Volume: ") +
(Config::Get(Config::MAIN_AUDIO_MUTED) ?
"Muted" :
std::to_string(Config::Get(Config::MAIN_AUDIO_VOLUME)) + "%"));
fmt::format("{}%", Config::Get(Config::MAIN_AUDIO_VOLUME))));
};
// Volume
@@ -14,6 +14,8 @@
#include <QStyle>
#include <QVBoxLayout>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/MathUtil.h"
@@ -395,7 +397,7 @@ void WiiTASInputWindow::LoadExtensionAndMotionPlus()
{
Common::IniFile ini;
ini.Load(File::GetUserPath(D_CONFIG_IDX) + "WiimoteNew.ini");
const std::string section_name = "Wiimote" + std::to_string(m_num + 1);
const std::string section_name = fmt::format("Wiimote{}", m_num + 1);
std::string extension;
ini.GetIfExists(section_name, "Extension", &extension);
@@ -7,6 +7,7 @@
#include <SDL3/SDL_gamepad.h>
#include <SDL3/SDL_haptic.h>
#include <fmt/format.h>
#include "Common/MathUtil.h"
@@ -16,17 +17,17 @@ namespace
{
std::string GetLegacyButtonName(int index)
{
return "Button " + std::to_string(index);
return fmt::format("Button {}", index);
}
std::string GetLegacyAxisName(int index, int range)
{
return "Axis " + std::to_string(index) + (range < 0 ? '-' : '+');
return fmt::format("Axis {}{}", index, range < 0 ? '-' : '+');
}
std::string GetLegacyHatName(int index, int direction)
{
return "Hat " + std::to_string(index) + ' ' + "NESW"[direction];
return fmt::format("Hat {} {}", index, "NESW"[direction]);
}
constexpr int GetDirectionFromHatMask(int mask)
@@ -14,6 +14,8 @@
#include <sys/eventfd.h>
#include <unistd.h>
#include <fmt/format.h>
#include "Common/Assert.h"
#include "Common/Flag.h"
#include "Common/Logging/Log.h"
@@ -114,7 +116,7 @@ protected:
}
}
std::string GetIndexedName() const { return "Button " + std::to_string(m_index); }
std::string GetIndexedName() const { return fmt::format("Button {}", m_index); }
const u8 m_index;
};
@@ -184,7 +186,7 @@ public:
protected:
std::string GetIndexedName() const
{
return "Axis " + std::to_string(m_index) + (m_range < 0 ? '-' : '+');
return fmt::format("Axis {}{}", m_index, m_range < 0 ? '-' : '+');
}
private:
+2 -2
View File
@@ -133,7 +133,7 @@ void ProfileCycler::CycleProfile(CycleDirection cycle_direction, InputConfig* de
}
else
{
Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index),
Core::DisplayMessage(fmt::format("No controller found for index: {}", controller_index),
display_message_ms);
}
}
@@ -172,7 +172,7 @@ void ProfileCycler::CycleProfileForGame(CycleDirection cycle_direction,
}
else
{
Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index),
Core::DisplayMessage(fmt::format("No controller found for index: {}", controller_index),
display_message_ms);
}
}
+2 -3
View File
@@ -622,7 +622,7 @@ std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database)
if (!GetGameID().empty())
info.push_back(GetGameID());
if (GetRevision() != 0)
info.push_back("Revision " + std::to_string(GetRevision()));
info.push_back(fmt::format("Revision {}", GetRevision()));
const std::string name = GetName(title_database);
@@ -635,8 +635,7 @@ std::string GameFile::GetNetPlayName(const Core::TitleDatabase& title_database)
if (disc_number > 1 && !is_numbered_disc)
{
std::string disc_text = "Disc ";
info.push_back(disc_text + std::to_string(disc_number));
info.push_back(fmt::format("Disc {}", disc_number));
}
if (info.empty())
return name;
+18 -13
View File
@@ -8,6 +8,7 @@
#include <span>
#include <string>
#include <fmt/format.h>
#include <picojson.h>
#include "Common/Common.h"
@@ -128,9 +129,12 @@ void NetPlayIndex::NotificationLoop()
{
Common::HttpRequest request;
auto response = request.Get(
Config::Get(Config::NETPLAY_INDEX_URL) + "/v0/session/active?secret=" + m_secret +
"&player_count=" + std::to_string(m_player_count) +
"&game=" + request.EscapeComponent(m_game) + "&in_game=" + std::to_string(m_in_game),
fmt::format(
"{base}/v0/session/active?secret={secret}&player_count={player_count}&game={game}"
"&in_game={in_game}",
fmt::arg("base", Config::Get(Config::NETPLAY_INDEX_URL)), fmt::arg("secret", m_secret),
fmt::arg("player_count", m_player_count),
fmt::arg("game", request.EscapeComponent(m_game)), fmt::arg("in_game", m_in_game)),
{{"X-Is-Dolphin", "1"}}, Common::HttpRequest::AllowedReturnCodes::All);
if (!response)
@@ -162,16 +166,17 @@ bool NetPlayIndex::Add(const NetPlaySession& session)
{
Common::HttpRequest request;
auto response = request.Get(
Config::Get(Config::NETPLAY_INDEX_URL) +
"/v0/session/add?name=" + request.EscapeComponent(session.name) +
"&region=" + request.EscapeComponent(session.region) +
"&game=" + request.EscapeComponent(session.game_id) +
"&password=" + std::to_string(session.has_password) + "&method=" + session.method +
"&server_id=" + session.server_id + "&in_game=" + std::to_string(session.in_game) +
"&port=" + std::to_string(session.port) + "&player_count=" +
std::to_string(session.player_count) + "&version=" + Common::GetScmDescStr(),
{{"X-Is-Dolphin", "1"}}, Common::HttpRequest::AllowedReturnCodes::All);
fmt::format("{base}/v0/session/add?name={name}&region={region}&game={game}"
"&password={password}&method={method}&server_id={server_id}&in_game={in_game}"
"&port={port}&player_count={player_count}&version={version}",
fmt::arg("base", Config::Get(Config::NETPLAY_INDEX_URL)),
fmt::arg("name", request.EscapeComponent(session.name)),
fmt::arg("region", request.EscapeComponent(session.region)),
fmt::arg("game", request.EscapeComponent(session.game_id)),
fmt::arg("password", session.has_password), fmt::arg("method", session.method),
fmt::arg("server_id", session.server_id), fmt::arg("in_game", session.in_game),
fmt::arg("port", session.port), fmt::arg("player_count", session.player_count),
fmt::arg("version", Common::GetScmDescStr())));
if (!response.has_value())
{
m_last_error = "NO_RESPONSE";
+3 -2
View File
@@ -10,6 +10,7 @@
#include <OptionParser.h>
#include <ed25519.h>
#include <fmt/format.h>
#include <mbedtls/base64.h>
#include <mbedtls/sha256.h>
#include <zlib.h>
@@ -225,8 +226,8 @@ static bool DownloadContent(std::span<const TodoList::DownloadOp> to_download,
if (File::Exists(temp_path + DIR_SEP + hash_filename))
continue;
UI::SetDescription("Downloading " + download.filename + "... (File " + std::to_string(i + 1) +
" of " + std::to_string(to_download.size()) + ")");
UI::SetDescription(fmt::format("Downloading {}... (File {} of {})", download.filename, i + 1,
to_download.size()));
UI::SetCurrentMarquee(false);
// Add slashes where needed.