summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorget <45425365+Minty-Meeo@users.noreply.github.com>2023-06-17 19:23:49 -0500
committerget <45425365+Minty-Meeo@users.noreply.github.com>2023-06-18 18:37:32 -0500
commitffabb6c57b59c6ceafd154681c2cde1bd1a65904 (patch)
tree05eb0486ca6620cdd18af9b65000bfa5be6ad104 /Source/Core
parent44498872e9dbf0c3d14397df2b4255ac2efe0f11 (diff)
Replace std::ostringstream usage with fmt::format
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/AudioCommon/WaveFile.cpp8
-rw-r--r--Source/Core/Common/Debug/Watches.cpp10
-rw-r--r--Source/Core/Core/NetPlayClient.cpp6
-rw-r--r--Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp11
-rw-r--r--Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp33
-rw-r--r--Source/Core/UICommon/UICommon.cpp8
6 files changed, 27 insertions, 49 deletions
diff --git a/Source/Core/AudioCommon/WaveFile.cpp b/Source/Core/AudioCommon/WaveFile.cpp
index 2e67d86519..b2345aca59 100644
--- a/Source/Core/AudioCommon/WaveFile.cpp
+++ b/Source/Core/AudioCommon/WaveFile.cpp
@@ -6,6 +6,8 @@
#include <string>
+#include <fmt/format.h>
+
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/IOFile.h"
@@ -159,9 +161,9 @@ void WaveFileWriter::AddStereoSamplesBE(const short* sample_data, u32 count,
{
Stop();
file_index++;
- std::ostringstream filename;
- filename << File::GetUserPath(D_DUMPAUDIO_IDX) << basename << file_index << ".wav";
- Start(filename.str(), sample_rate_divisor);
+ const std::string filename =
+ fmt::format("{}{}{}.wav", File::GetUserPath(D_DUMPAUDIO_IDX), basename, file_index);
+ Start(filename, sample_rate_divisor);
current_sample_rate_divisor = sample_rate_divisor;
}
diff --git a/Source/Core/Common/Debug/Watches.cpp b/Source/Core/Common/Debug/Watches.cpp
index dddb3f3435..c476665a41 100644
--- a/Source/Core/Common/Debug/Watches.cpp
+++ b/Source/Core/Common/Debug/Watches.cpp
@@ -7,6 +7,8 @@
#include <locale>
#include <sstream>
+#include <fmt/format.h>
+
namespace Common::Debug
{
Watch::Watch(u32 address_, std::string name_, State is_enabled_)
@@ -107,13 +109,9 @@ void Watches::LoadFromStrings(const std::vector<std::string>& watches)
std::vector<std::string> Watches::SaveToStrings() const
{
std::vector<std::string> watches;
+ watches.reserve(m_watches.size());
for (const auto& watch : m_watches)
- {
- std::ostringstream ss;
- ss.imbue(std::locale::classic());
- ss << std::hex << watch.address << " " << watch.name;
- watches.push_back(ss.str());
- }
+ watches.emplace_back(fmt::format("{:x} {}", watch.address, watch.name));
return watches;
}
diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp
index ff78728c80..014bd3b523 100644
--- a/Source/Core/Core/NetPlayClient.cpp
+++ b/Source/Core/Core/NetPlayClient.cpp
@@ -11,7 +11,6 @@
#include <memory>
#include <mutex>
#include <span>
-#include <sstream>
#include <thread>
#include <tuple>
#include <type_traits>
@@ -535,10 +534,7 @@ void NetPlayClient::OnChatMessage(sf::Packet& packet)
INFO_LOG_FMT(NETPLAY, "Player {} ({}) wrote: {}", player.name, player.pid, msg);
// add to gui
- std::ostringstream ss;
- ss << player.name << '[' << char(pid + '0') << "]: " << msg;
-
- m_dialog->AppendChat(ss.str());
+ m_dialog->AppendChat(fmt::format("{}[{}]: {}", player.name, pid, msg));
}
void NetPlayClient::OnChunkedDataStart(sf::Packet& packet)
diff --git a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp
index 222791f03f..28b91332cc 100644
--- a/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/CoreDevice.cpp
@@ -162,15 +162,12 @@ void Device::AddCombinedInput(std::string name, const std::pair<std::string, std
std::string DeviceQualifier::ToString() const
{
if (source.empty() && (cid < 0) && name.empty())
- return "";
+ return {};
- std::ostringstream ss;
- ss << source << '/';
if (cid > -1)
- ss << cid;
- ss << '/' << name;
-
- return ss.str();
+ return fmt::format("{}/{}/{}", source, cid, name);
+ else
+ return fmt::format("{}//{}", source, name);
}
//
diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp
index abef48f157..eb60721b2f 100644
--- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp
@@ -7,9 +7,10 @@
#include <limits>
#include <mutex>
#include <set>
-#include <sstream>
#include <type_traits>
+#include <fmt/format.h>
+
#include "Common/HRWrap.h"
#include "Common/Logging/Log.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
@@ -266,37 +267,21 @@ void Joystick::UpdateInput()
std::string Joystick::Button::GetName() const
{
- std::ostringstream ss;
- ss << "Button " << (int)m_index;
- return ss.str();
+ return fmt::format("Button {}", m_index);
}
std::string Joystick::Axis::GetName() const
{
- std::ostringstream ss;
- // axis
- if (m_index < 6)
- {
- ss << "Axis " << (char)('X' + (m_index % 3));
- if (m_index > 2)
- ss << 'r';
- }
- // slider
- else
- {
- ss << "Slider " << (int)(m_index - 6);
- }
-
- ss << (m_range < 0 ? '-' : '+');
- return ss.str();
+ const char sign = m_range < 0 ? '-' : '+';
+ if (m_index < 6) // axis
+ return fmt::format("Axis {:c}{}{:c}", 'X' + m_index % 3, m_index > 2 ? "r" : "", sign);
+ else // slider
+ return fmt::format("Slider {}{:c}", m_index - 6, sign);
}
std::string Joystick::Hat::GetName() const
{
- char tmpstr[] = "Hat . .";
- tmpstr[4] = (char)('0' + m_index);
- tmpstr[6] = "NESW"[m_direction];
- return tmpstr;
+ return fmt::format("Hat {} {:c}", m_index, "NESW"[m_direction]);
}
// get / set state
diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp
index 464646eb17..2acd69f2c2 100644
--- a/Source/Core/UICommon/UICommon.cpp
+++ b/Source/Core/UICommon/UICommon.cpp
@@ -16,6 +16,8 @@
#include <wil/resource.h>
#endif
+#include <fmt/format.h>
+
#include "Common/Common.h"
#include "Common/CommonPaths.h"
#include "Common/Config/Config.h"
@@ -551,10 +553,8 @@ std::string FormatSize(u64 bytes, int decimals)
// Don't need exact values, only 5 most significant digits
const double unit_size = std::pow(2, unit * 10);
- std::ostringstream ss;
- ss << std::fixed << std::setprecision(decimals);
- ss << bytes / unit_size << ' ' << Common::GetStringT(unit_symbols[unit]);
- return ss.str();
+ return fmt::format("{:.{}Lf} {}", bytes / unit_size, decimals,
+ Common::GetStringT(unit_symbols[unit]));
}
} // namespace UICommon