Core: Replace usages of StringFromFormat with fmt where applicable

Migrates usages of StringFromFormat over to using fmt.
This commit is contained in:
Lioncash committed 2019-11-11 07:32:57 -05:00
1 parent 6282b0d83e
commit febd1c3dba
30 files changed
+192 -165

No files matched your search

+8 -6
View File
@@ -17,6 +17,8 @@
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"
@@ -91,7 +93,7 @@ void DSPAssembler::ShowError(AssemblerError err_code, const char* extra_info)
if (!m_settings.force)
m_failed = true;
std::string error = StringFromFormat("%u : %s ", m_code_line, m_cur_line.c_str());
std::string error = fmt::format("{} : {} ", m_code_line, m_cur_line);
if (!extra_info)
extra_info = "-";
@@ -99,12 +101,12 @@ void DSPAssembler::ShowError(AssemblerError err_code, const char* extra_info)
if (m_current_param == 0)
{
error += StringFromFormat("ERROR: %s Line: %u : %s\n", error_string, m_code_line, extra_info);
error += fmt::format("ERROR: {} Line: {} : {}\n", error_string, m_code_line, extra_info);
}
else
{
error += StringFromFormat("ERROR: %s Line: %u Param: %d : %s\n", error_string, m_code_line,
m_current_param, extra_info);
error += fmt::format("ERROR: {} Line: {} Param: {} : {}\n", error_string, m_code_line,
m_current_param, extra_info);
}
m_last_error_str = std::move(error);
@@ -958,8 +960,8 @@ bool DSPAssembler::AssemblePass(const std::string& text, int pass)
{
if (m_cur_addr > params[0].val)
{
std::string msg = StringFromFormat("WARNPC at 0x%04x, expected 0x%04x or less",
m_cur_addr, params[0].val);
const std::string msg = fmt::format("WARNPC at 0x{:04x}, expected 0x{:04x} or less",
m_cur_addr, params[0].val);
ShowError(AssemblerError::PCOutOfRange, msg.c_str());
}
}
+3 -1
View File
@@ -9,6 +9,8 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
@@ -147,7 +149,7 @@ bool SaveBinary(const std::vector<u16>& code, const std::string& filename)
bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc)
{
const std::string root_name =
File::GetUserPath(D_DUMPDSP_IDX) + StringFromFormat("DSP_UC_%08X", crc);
File::GetUserPath(D_DUMPDSP_IDX) + fmt::format("DSP_UC_{:08X}", crc);
const std::string binary_file = root_name + ".bin";
const std::string text_file = root_name + ".txt";
+25 -18
View File
@@ -10,6 +10,8 @@
#include <string>
#include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
@@ -73,16 +75,16 @@ std::string DSPDisassembler::DisassembleParameters(const DSPOPCTemplate& opc, u1
{
case P_REG:
if (settings_.decode_registers)
buf += StringFromFormat("$%s", pdregname(val));
buf += fmt::format("${}", pdregname(val));
else
buf += StringFromFormat("$%d", val);
buf += fmt::format("${}", val);
break;
case P_PRG:
if (settings_.decode_registers)
buf += StringFromFormat("@$%s", pdregname(val));
buf += fmt::format("@${}", pdregname(val));
else
buf += StringFromFormat("@$%d", val);
buf += fmt::format("@${}", val);
break;
case P_VAL:
@@ -94,22 +96,27 @@ std::string DSPDisassembler::DisassembleParameters(const DSPOPCTemplate& opc, u1
}
else
{
buf += StringFromFormat("0x%04x", val);
buf += fmt::format("0x{:04x}", val);
}
break;
case P_IMM:
if (opc.params[j].size != 2)
{
if (opc.params[j].mask == 0x003f) // LSL, LSR, ASL, ASR
buf += StringFromFormat("#%d",
(val & 0x20) ? (val | 0xFFFFFFC0) : val); // 6-bit sign extension
// LSL, LSR, ASL, ASR
if (opc.params[j].mask == 0x003f)
{
// 6-bit sign extension
buf += fmt::format("#{}", (val & 0x20) != 0 ? (val | 0xFFFFFFC0) : val);
}
else
buf += StringFromFormat("#0x%02x", val);
{
buf += fmt::format("#0x{:02x}", val);
}
}
else
{
buf += StringFromFormat("#0x%04x", val);
buf += fmt::format("#0x{:04x}", val);
}
break;
@@ -118,9 +125,9 @@ std::string DSPDisassembler::DisassembleParameters(const DSPOPCTemplate& opc, u1
val = (u16)(s16)(s8)val;
if (settings_.decode_names)
buf += StringFromFormat("@%s", pdname(val));
buf += fmt::format("@{}", pdname(val));
else
buf += StringFromFormat("@0x%04x", val);
buf += fmt::format("@0x{:04x}", val);
break;
default:
@@ -174,7 +181,7 @@ bool DSPDisassembler::DisassembleOpcode(const u16* binbuf, u16* pc, std::string&
// printing
if (settings_.show_pc)
dest += StringFromFormat("%04x ", *pc);
dest += fmt::format("{:04x} ", *pc);
u16 op2;
@@ -183,25 +190,25 @@ bool DSPDisassembler::DisassembleOpcode(const u16* binbuf, u16* pc, std::string&
{
op2 = binbuf[(*pc + 1) & 0x0fff];
if (settings_.show_hex)
dest += StringFromFormat("%04x %04x ", op1, op2);
dest += fmt::format("{:04x} {:04x} ", op1, op2);
}
else
{
op2 = 0;
if (settings_.show_hex)
dest += StringFromFormat("%04x ", op1);
dest += fmt::format("{:04x} ", op1);
}
std::string opname = opc->name;
if (is_extended)
opname += StringFromFormat("%c%s", settings_.ext_separator, opc_ext->name);
opname += fmt::format("{}{}", settings_.ext_separator, opc_ext->name);
if (settings_.lower_case_ops)
std::transform(opname.begin(), opname.end(), opname.begin(), ::tolower);
if (settings_.print_tabs)
dest += StringFromFormat("%s\t", opname.c_str());
dest += fmt::format("{}\t", opname);
else
dest += StringFromFormat("%-12s", opname.c_str());
dest += fmt::format("{:<12}", opname);
if (opc->param_count > 0)
dest += DisassembleParameters(*opc, op1, op2);