Replace std::ostringstream usage with fmt::format

This commit is contained in:
get
2023-06-17 19:23:49 -05:00
parent 44498872e9
commit ffabb6c57b
6 changed files with 27 additions and 49 deletions

View File

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

View File

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