From 5b92d5076a0be89945fa0fc722749dd5fbfcdf4c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 14 Jun 2019 10:53:46 -0400 Subject: Common: Use fmt where applicable Begins the transition to using fmt for string formatting where applicable. Given fmt supports formatting std::string instances out of the box, we can remove now-unnecessary calls to .c_str() and .data(). Note that this change does not touch the actual logging subsystem aside from converting the final StringFromFormat call in the process over to fmt::format. Given our logging system is heavily used throughout the entire codebase, and converting that over will be quite a large change by itself, this will be tackled near the end of the conversion process. --- Source/Core/Common/StringUtil.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'Source/Core/Common/StringUtil.cpp') diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index b946cfd450..0df4b595cd 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -2,8 +2,9 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "Common/StringUtil.h" + #include -#include #include #include #include @@ -18,11 +19,12 @@ #include #include +#include + #include "Common/CommonFuncs.h" #include "Common/CommonPaths.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" -#include "Common/StringUtil.h" #include "Common/Swap.h" #ifdef _WIN32 @@ -51,12 +53,12 @@ std::string HexDump(const u8* data, size_t size) std::string out; for (size_t row_start = 0; row_start < size; row_start += BYTES_PER_LINE) { - out += StringFromFormat("%06zx: ", row_start); + out += fmt::format("{:06x}: ", row_start); for (size_t i = 0; i < BYTES_PER_LINE; ++i) { if (row_start + i < size) { - out += StringFromFormat("%02hhx ", data[row_start + i]); + out += fmt::format("{:02x} ", data[row_start + i]); } else { @@ -294,27 +296,27 @@ bool TryParse(const std::string& str, bool* const output) std::string ValueToString(u16 value) { - return StringFromFormat("0x%04x", value); + return fmt::format("0x{:04x}", value); } std::string ValueToString(u32 value) { - return StringFromFormat("0x%08x", value); + return fmt::format("0x{:08x}", value); } std::string ValueToString(u64 value) { - return StringFromFormat("0x%016" PRIx64, value); + return fmt::format("0x{:016x}", value); } std::string ValueToString(float value) { - return StringFromFormat("%#.9g", value); + return fmt::format("{:#.9g}", value); } std::string ValueToString(double value) { - return StringFromFormat("%#.17g", value); + return fmt::format("{:#.17g}", value); } std::string ValueToString(int value) @@ -324,7 +326,7 @@ std::string ValueToString(int value) std::string ValueToString(s64 value) { - return StringFromFormat("%" PRId64, value); + return std::to_string(value); } std::string ValueToString(bool value) -- cgit v1.2.3