diff --git a/Core/Config.cpp b/Core/Config.cpp index d28e9c2494..52d5e3a847 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "base/display.h" #include "base/NativeApp.h" diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index da0617dd43..462aa02dbf 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "file/file_util.h" #ifdef SHARED_LIBZIP diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index e8898c144b..9986f1a523 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "profiler/profiler.h" diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 03296a8f28..1533e21d5d 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "CommonWindows.h" #include diff --git a/ext/native/base/stringutil.cpp b/ext/native/base/stringutil.cpp index 2861f844d3..3b42400c88 100644 --- a/ext/native/base/stringutil.cpp +++ b/ext/native/base/stringutil.cpp @@ -8,8 +8,8 @@ #define _GNU_SOURCE #include #endif -#include -#include +#include +#include #include #include #include @@ -240,6 +240,7 @@ bool TryParse(const std::string &str, uint32_t *const output) if (errno == ERANGE) return false; + // Range check if (ULONG_MAX > UINT_MAX) { #ifdef _MSC_VER #pragma warning (disable:4309) @@ -266,6 +267,30 @@ bool TryParse(const std::string &str, bool *const output) return true; } +template +bool TryParseImpl(const std::string &str, N *const output) { + std::istringstream iss(str); + N tmp = 0; + if (iss >> tmp) { + *output = tmp; + return true; + } else { + return false; + } +} + +bool TryParse(const std::string &str, int32_t *const output) { + return TryParseImpl(str, output); +} + +bool TryParse(const std::string &str, float *const output) { + return TryParseImpl(str, output); +} + +bool TryParse(const std::string &str, double *const output) { + return TryParseImpl(str, output); +} + void SplitString(const std::string& str, const char delim, std::vector& output) { size_t next = 0; diff --git a/ext/native/base/stringutil.h b/ext/native/base/stringutil.h index c16602946f..255b588322 100644 --- a/ext/native/base/stringutil.h +++ b/ext/native/base/stringutil.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include "base/basictypes.h" @@ -37,7 +36,7 @@ inline bool startsWith(const std::string &str, const std::string &what) { inline bool endsWith(const std::string &str, const std::string &what) { if (str.size() < what.size()) return false; - return str.substr(str.size() - what.size()) == what; + return str.substr(str.size() - what.size()) == what; } // Only use on strings where you're only concerned about ASCII. @@ -56,10 +55,9 @@ inline bool endsWithNoCase(const std::string &str, const std::string &what) { void DataToHexString(const uint8_t *data, size_t size, std::string *output); inline void StringToHexString(const std::string &data, std::string *output) { - DataToHexString((uint8_t *)(&data[0]), data.size(), output); + DataToHexString((uint8_t *)(&data[0]), data.size(), output); } - // highly unsafe and not recommended. unsigned int parseHex(const char* _szValue); @@ -74,21 +72,10 @@ std::string StripQuotes(const std::string &s); bool TryParse(const std::string &str, bool *const output); bool TryParse(const std::string &str, uint32_t *const output); +bool TryParse(const std::string &str, int32_t *const output); +bool TryParse(const std::string &str, float *const output); +bool TryParse(const std::string &str, double *const output); -template -static bool TryParse(const std::string &str, N *const output) -{ - std::istringstream iss(str); - - N tmp = 0; - if (iss >> tmp) - { - *output = tmp; - return true; - } - else - return false; -} void SplitString(const std::string& str, const char delim, std::vector& output); void GetQuotedStrings(const std::string& str, std::vector& output); @@ -98,14 +85,6 @@ std::string ReplaceAll(std::string input, const std::string& src, const std::str // Compare two strings, ignore the difference between the ignorestr1 and the ignorestr2 in str1 and str2. int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std::string ignorestr2); -template -static std::string ValueToString(const N value) -{ - std::stringstream string; - string << value; - return string.str(); -} - void StringTrimEndNonAlphaNum(char *str); void SkipSpace(const char **ptr); void StringUpper(char *str); diff --git a/ext/native/file/ini_file.cpp b/ext/native/file/ini_file.cpp index 99bdcd163a..79a9f3ff8f 100644 --- a/ext/native/file/ini_file.cpp +++ b/ext/native/file/ini_file.cpp @@ -2,8 +2,8 @@ // Taken from Dolphin but relicensed by me, Henrik Rydgard, under the MIT // license as I wrote the whole thing originally and it has barely changed. -#include -#include +#include +#include #ifndef _MSC_VER #include @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "base/logging.h" diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index ba63ab1ab5..1c8d1e3976 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -10,6 +10,14 @@ #include "base/stringutil.h" +template +inline std::string ValueToString(const N value) +{ + std::stringstream string; + string << value; + return string.str(); +} + class IniFile { public: diff --git a/ext/native/i18n/i18n.h b/ext/native/i18n/i18n.h index 75d8ddd776..cdffed3a29 100644 --- a/ext/native/i18n/i18n.h +++ b/ext/native/i18n/i18n.h @@ -9,7 +9,6 @@ // As usual, everything is UTF-8. Nothing else allowed. #include -#include #include #include #include diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index e2dba2cf60..3bfa8dcfe1 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -1,5 +1,7 @@ #include #include +#include + #include "base/display.h" #include "input/input_state.h" #include "input/keycodes.h"