Merge pull request #11972 from Minty-Meeo/string-improvements-part-1c
Replace std::ostringstream usage with fmt::format
This commit is contained in:
commit
5d7b5822c9
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue