diff --git a/Source/Core/Common/Config/Layer.cpp b/Source/Core/Common/Config/Layer.cpp index 6653dbfe65..8eba0d7c1a 100644 --- a/Source/Core/Common/Config/Layer.cpp +++ b/Source/Core/Common/Config/Layer.cpp @@ -11,44 +11,6 @@ namespace Config { -namespace detail -{ -std::string ValueToString(u16 value) -{ - return StringFromFormat("0x%04x", value); -} - -std::string ValueToString(u32 value) -{ - return StringFromFormat("0x%08x", value); -} - -std::string ValueToString(float value) -{ - return StringFromFormat("%#.9g", value); -} - -std::string ValueToString(double value) -{ - return StringFromFormat("%#.17g", value); -} - -std::string ValueToString(int value) -{ - return std::to_string(value); -} - -std::string ValueToString(bool value) -{ - return StringFromBool(value); -} - -std::string ValueToString(const std::string& value) -{ - return value; -} -} - ConfigLayerLoader::ConfigLayerLoader(LayerType layer) : m_layer(layer) { } diff --git a/Source/Core/Common/Config/Layer.h b/Source/Core/Common/Config/Layer.h index 3e01b83fed..4fabb3dc81 100644 --- a/Source/Core/Common/Config/Layer.h +++ b/Source/Core/Common/Config/Layer.h @@ -19,19 +19,6 @@ namespace Config { namespace detail { -std::string ValueToString(u16 value); -std::string ValueToString(u32 value); -std::string ValueToString(float value); -std::string ValueToString(double value); -std::string ValueToString(int value); -std::string ValueToString(bool value); -std::string ValueToString(const std::string& value); -template ::value>* = nullptr> -std::string ValueToString(T value) -{ - return ValueToString(static_cast>(value)); -} - template ::value>* = nullptr> std::optional TryParse(const std::string& str_value) { @@ -139,7 +126,7 @@ public: template void Set(const ConfigLocation& location, const T& value) { - const std::string new_value = detail::ValueToString(value); + const std::string new_value = ValueToString(value); std::optional& current_value = m_map[location]; if (current_value == new_value) return; diff --git a/Source/Core/Common/IniFile.cpp b/Source/Core/Common/IniFile.cpp index ddaf64b0e3..d28092261c 100644 --- a/Source/Core/Common/IniFile.cpp +++ b/Source/Core/Common/IniFile.cpp @@ -103,7 +103,7 @@ void IniFile::Section::Set(const std::string& key, s64 newValue) void IniFile::Section::Set(const std::string& key, bool newValue) { - Set(key, StringFromBool(newValue)); + Set(key, ValueToString(newValue)); } bool IniFile::Section::Get(const std::string& key, std::string* value, diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index cc1ffaa949..372ea06c19 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -291,11 +292,51 @@ bool TryParse(const std::string& str, bool* const output) return true; } -std::string StringFromBool(bool value) +std::string ValueToString(u16 value) +{ + return StringFromFormat("0x%04x", value); +} + +std::string ValueToString(u32 value) +{ + return StringFromFormat("0x%08x", value); +} + +std::string ValueToString(u64 value) +{ + return StringFromFormat("0x%016" PRIx64, value); +} + +std::string ValueToString(float value) +{ + return StringFromFormat("%#.9g", value); +} + +std::string ValueToString(double value) +{ + return StringFromFormat("%#.17g", value); +} + +std::string ValueToString(int value) +{ + return std::to_string(value); +} + +std::string ValueToString(s64 value) +{ + return StringFromFormat("%" PRId64, value); +} + +std::string ValueToString(bool value) { return value ? "True" : "False"; } +std::string ValueToString(const std::string& value) +{ + return value; +} + bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename, std::string* _pExtension) { diff --git a/Source/Core/Common/StringUtil.h b/Source/Core/Common/StringUtil.h index 2e6089ef14..c548b0e87c 100644 --- a/Source/Core/Common/StringUtil.h +++ b/Source/Core/Common/StringUtil.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "Common/CommonTypes.h" @@ -41,8 +42,6 @@ std::string ArrayToString(const u8* data, u32 size, int line_len = 20, bool spac std::string StripSpaces(const std::string& s); std::string StripQuotes(const std::string& s); -std::string StringFromBool(bool value); - bool TryParse(const std::string& str, bool* output); bool TryParse(const std::string& str, u16* output); bool TryParse(const std::string& str, u32* output); @@ -83,6 +82,21 @@ bool TryParseVector(const std::string& str, std::vector* output, const char d return true; } +std::string ValueToString(u16 value); +std::string ValueToString(u32 value); +std::string ValueToString(u64 value); +std::string ValueToString(float value); +std::string ValueToString(double value); +std::string ValueToString(int value); +std::string ValueToString(s64 value); +std::string ValueToString(bool value); +std::string ValueToString(const std::string& value); +template ::value>* = nullptr> +std::string ValueToString(T value) +{ + return ValueToString(static_cast>(value)); +} + // Generates an hexdump-like representation of a binary data blob. std::string HexDump(const u8* data, size_t size); diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index e2ca7038c0..bc8da4d92b 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -30,7 +30,7 @@ public: if (audio_backend.size()) m_values.emplace_back( - std::make_tuple(Config::MAIN_DSP_HLE.location, StringFromBool(audio_backend == "HLE"))); + std::make_tuple(Config::MAIN_DSP_HLE.location, ValueToString(audio_backend == "HLE"))); // Arguments are in the format of .
.=Value for (const auto& arg : args)