From ed88761ecc1d1a2dd023a89189c1b6fdca65b033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 29 Sep 2020 12:19:22 +0200 Subject: [PATCH] Merge ext/native/stringutil.cpp/h into Common/StringUtils.cpp/h. --- CMakeLists.txt | 3 - Common/ConsoleListener.cpp | 5 +- Common/KeyMap.cpp | 2 +- Common/Misc.cpp | 6 +- Common/StringUtils.cpp | 203 ++++++++++++++++++ Common/StringUtils.h | 60 +++++- Core/Debugger/WebSocket/DisasmSubscriber.cpp | 4 +- Core/Debugger/WebSocket/HLESubscriber.cpp | 2 +- .../Debugger/WebSocket/SteppingSubscriber.cpp | 2 +- Core/Dialog/PSPSaveDialog.cpp | 2 +- Core/FileLoaders/HTTPFileLoader.cpp | 2 +- Core/FileSystems/DirectoryFileSystem.cpp | 3 +- Core/HLE/sceKernelModule.cpp | 1 - Core/HLE/sceKernelThread.cpp | 1 + Core/Loaders.cpp | 2 +- Core/Reporting.cpp | 9 +- Core/SaveState.cpp | 2 +- Core/TextureReplacer.cpp | 3 +- Core/Util/PPGeDraw.cpp | 2 +- Core/WebServer.cpp | 6 +- GPU/Common/PostShader.cpp | 1 + GPU/Common/ShaderTranslation.cpp | 3 +- GPU/D3D11/D3D11Util.cpp | 7 +- GPU/Debugger/Record.cpp | 4 +- GPU/Directx9/ShaderManagerDX9.cpp | 3 +- GPU/Directx9/VertexShaderGeneratorDX9.cpp | 4 +- GPU/GLES/VertexShaderGeneratorGLES.cpp | 2 +- GPU/Vulkan/ShaderManagerVulkan.cpp | 2 +- GPU/Vulkan/TextureCacheVulkan.cpp | 1 + GPU/Vulkan/VertexShaderGeneratorVulkan.cpp | 2 +- GPU/Vulkan/VulkanUtil.cpp | 3 +- UI/ComboKeyMappingScreen.cpp | 10 +- UI/CwCheatScreen.cpp | 2 +- UI/DevScreens.cpp | 2 +- UI/GameInfoCache.cpp | 1 - UI/GameSettingsScreen.cpp | 4 +- UI/MainScreen.cpp | 2 +- UI/NativeApp.cpp | 4 +- UI/PauseScreen.cpp | 4 +- UI/RemoteISOScreen.cpp | 3 +- UI/ReportScreen.cpp | 2 +- UI/SavedataScreen.cpp | 2 +- UWP/NativeUWP/NativeUWP.vcxproj | 2 - UWP/NativeUWP/NativeUWP.vcxproj.filters | 6 - Windows/Debugger/Debugger_Disasm.cpp | 3 +- Windows/GEDebugger/GEDebugger.cpp | 2 +- Windows/GPU/WindowsVulkanContext.cpp | 1 - Windows/MainWindow.cpp | 2 +- Windows/MainWindowMenu.cpp | 2 +- Windows/main.cpp | 2 +- android/jni/app-android.cpp | 3 +- ext/native/Android.mk | 1 - ext/native/base/basictypes.h | 2 - ext/native/base/stringutil.cpp | 198 ----------------- ext/native/base/stringutil.h | 62 ------ ext/native/file/file_util.cpp | 19 +- ext/native/file/file_util.h | 1 - ext/native/file/ini_file.cpp | 19 +- ext/native/file/ini_file.h | 17 +- ext/native/file/path.cpp | 4 +- ext/native/gfx_es2/draw_buffer.cpp | 2 +- ext/native/gfx_es2/draw_text.cpp | 1 - ext/native/gfx_es2/draw_text_android.cpp | 1 - ext/native/gfx_es2/draw_text_qt.cpp | 1 - ext/native/gfx_es2/draw_text_uwp.cpp | 1 - ext/native/gfx_es2/draw_text_win.cpp | 2 +- ext/native/gfx_es2/gpu_features.cpp | 2 +- ext/native/i18n/i18n.cpp | 3 +- ext/native/native.vcxproj | 2 - ext/native/native.vcxproj.filters | 6 - ext/native/net/http_client.cpp | 3 +- ext/native/net/http_headers.cpp | 2 +- ext/native/net/url.cpp | 2 +- ext/native/net/websocket_server.cpp | 2 +- ext/native/thin3d/GLQueueRunner.cpp | 2 +- ext/native/thin3d/VulkanRenderManager.cpp | 1 + ext/native/thin3d/VulkanRenderManager.h | 1 - ext/native/thin3d/thin3d_vulkan.cpp | 2 +- ext/native/ui/ui_screen.cpp | 2 +- ext/native/ui/view.cpp | 2 +- ext/native/ui/viewgroup.cpp | 2 +- ext/native/util/text/parsers.cpp | 3 +- libretro/Makefile.common | 1 - 83 files changed, 381 insertions(+), 399 deletions(-) delete mode 100644 ext/native/base/stringutil.cpp delete mode 100644 ext/native/base/stringutil.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b2804099bd..e61c638d9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -946,9 +946,6 @@ add_library(native STATIC ext/native/base/colorutil.h ext/native/base/display.cpp ext/native/base/display.h - ext/native/base/linked_ptr.h - ext/native/base/stringutil.cpp - ext/native/base/stringutil.h ext/native/data/base64.cpp ext/native/data/base64.h ext/native/data/compression.cpp diff --git a/Common/ConsoleListener.cpp b/Common/ConsoleListener.cpp index 7eab9980c9..da44073795 100644 --- a/Common/ConsoleListener.cpp +++ b/Common/ConsoleListener.cpp @@ -34,8 +34,9 @@ #include "ppsspp_config.h" #include "thread/threadutil.h" #include "util/text/utf8.h" -#include "Common.h" -#include "ConsoleListener.h" // Common +#include "Common/Common.h" +#include "Common/ConsoleListener.h" +#include "Common/StringUtils.h" #if defined(USING_WIN_UI) const int LOG_PENDING_MAX = 120 * 10000; diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index 19b93711df..99d3bf4f05 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -24,7 +24,6 @@ #include "CommonWindows.h" #endif -#include "base/stringutil.h" #include "base/NativeApp.h" #include "file/ini_file.h" #include "input/input_state.h" @@ -32,6 +31,7 @@ #include "Common/Log.h" #include "Common/KeyMap.h" +#include "Common/StringUtils.h" #include "Core/HLE/sceUtility.h" #include "Core/Config.h" diff --git a/Common/Misc.cpp b/Common/Misc.cpp index af573729b9..a13924b1bf 100644 --- a/Common/Misc.cpp +++ b/Common/Misc.cpp @@ -43,16 +43,16 @@ const char *GetLastErrorMsg() const char *GetStringErrorMsg(int errCode) { static const size_t buff_size = 1023; #ifdef _WIN32 - static __THREAD wchar_t err_strw[buff_size] = {}; + static thread_local wchar_t err_strw[buff_size] = {}; FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_strw, buff_size, NULL); - static __THREAD char err_str[buff_size] = {}; + static thread_local char err_str[buff_size] = {}; snprintf(err_str, buff_size, "%s", ConvertWStringToUTF8(err_strw).c_str()); #else - static __thread char err_str[buff_size] = {}; + static thread_local char err_str[buff_size] = {}; // Thread safe (XSI-compliant) if (strerror_r(errCode, err_str, buff_size) == 0) { diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 58d721a1e4..b5a2d3b987 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -16,6 +16,33 @@ // http://code.google.com/p/dolphin-emu/ #include + +#include "ppsspp_config.h" + +#ifdef _WIN32 +#include +#undef min +#undef max +#endif + +#if PPSSPP_PLATFORM(SWITCH) +#define _GNU_SOURCE +#include +#endif + +#include + +#include + +#include +#include +#include + +#include +#include + +#include "base/buffer.h" + #include "Common.h" #include "StringUtils.h" @@ -114,3 +141,179 @@ std::string GetFilenameFromPath(std::string full_path) { // No directory components, just return the full path. return full_path; } + +std::string LineNumberString(const std::string &str) { + std::stringstream input(str); + std::stringstream output; + std::string line; + + int lineNumber = 1; + while (std::getline(input, line)) { + output << std::setw(4) << lineNumber++ << ": " << line << std::endl; + } + + return output.str(); +} + +void SkipSpace(const char **ptr) { + while (**ptr && isspace(**ptr)) { + (*ptr)++; + } +} + +void DataToHexString(const uint8_t *data, size_t size, std::string *output) { + Buffer buffer; + for (size_t i = 0; i < size; i++) { + if (i && !(i & 15)) + buffer.Printf("\n"); + buffer.Printf("%02x ", data[i]); + } + buffer.TakeAll(output); +} + +void DataToHexString(const char* prefix, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output) { + Buffer buffer; + size_t i = 0; + for (; i < size; i++) { + if (i && !(i & 15)) { + buffer.Printf(" "); + for (size_t j = i - 16; j < i; j++) { + buffer.Printf("%c", ((data[j] < 0x20) || (data[j] > 0x7e)) ? 0x2e : data[j]); + } + buffer.Printf("\n"); + } + if (!(i & 15)) + buffer.Printf("%s%08x ", prefix, startAddr + i); + buffer.Printf("%02x ", data[i]); + } + if (size & 15) { + size_t padded_size = ((size - 1) | 15) + 1; + for (size_t j = size; j < padded_size; j++) { + buffer.Printf(" "); + } + buffer.Printf(" "); + for (size_t j = size & ~UINT64_C(0xF); j < size; j++) { + buffer.Printf("%c", ((data[j] < 0x20) || (data[j] > 0x7e)) ? 0x2e : data[j]); + } + } + buffer.TakeAll(output); +} + +std::string StringFromFormat(const char* format, ...) +{ + va_list args; + std::string temp = ""; +#ifdef _WIN32 + int required = 0; + + va_start(args, format); + required = _vscprintf(format, args); + // Using + 2 to be safe between MSVC versions. + // In MSVC 2015 and later, vsnprintf counts the trailing zero (per c++11.) + temp.resize(required + 2); + if (vsnprintf(&temp[0], required + 1, format, args) < 0) { + temp.resize(0); + } else { + temp.resize(required); + } + va_end(args); +#else + char *buf = nullptr; + + va_start(args, format); + if (vasprintf(&buf, format, args) < 0) + buf = nullptr; + va_end(args); + + if (buf != nullptr) { + temp = buf; + free(buf); + } +#endif + return temp; +} + +std::string StringFromInt(int value) +{ + char temp[16]; + sprintf(temp, "%i", value); + return temp; +} + +// Turns " hej " into "hej". Also handles tabs. +std::string StripSpaces(const std::string &str) +{ + const size_t s = str.find_first_not_of(" \t\r\n"); + + if (str.npos != s) + return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); + else + return ""; +} + +// "\"hello\"" is turned to "hello" +// This one assumes that the string has already been space stripped in both +// ends, as done by StripSpaces above, for example. +std::string StripQuotes(const std::string& s) +{ + if (s.size() && '\"' == s[0] && '\"' == *s.rbegin()) + return s.substr(1, s.size() - 2); + else + return s; +} + +void SplitString(const std::string& str, const char delim, std::vector& output) +{ + size_t next = 0; + for (size_t pos = 0, len = str.length(); pos < len; ++pos) { + if (str[pos] == delim) { + output.push_back(str.substr(next, pos - next)); + // Skip the delimiter itself. + next = pos + 1; + } + } + + if (next == 0) { + output.push_back(str); + } else if (next < str.length()) { + output.push_back(str.substr(next)); + } +} + +void GetQuotedStrings(const std::string& str, std::vector& output) +{ + size_t next = 0; + bool even = 0; + for (size_t pos = 0, len = str.length(); pos < len; ++pos) { + if (str[pos] == '\"' || str[pos] == '\'') { + if (even) { + //quoted text + output.push_back(str.substr(next, pos - next)); + even = 0; + } else { + //non quoted text + even = 1; + } + // Skip the delimiter itself. + next = pos + 1; + } + } +} + +std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) +{ + size_t pos = 0; + + if (src == dest) + return result; + + while (1) + { + pos = result.find(src, pos); + if (pos == result.npos) + break; + result.replace(pos, src.size(), dest); + pos += dest.size(); + } + return result; +} diff --git a/Common/StringUtils.h b/Common/StringUtils.h index 58d433697c..0cc81c6cd3 100644 --- a/Common/StringUtils.h +++ b/Common/StringUtils.h @@ -17,10 +17,66 @@ #pragma once -#include - #include "Common.h" +#include +#include + +#ifdef _MSC_VER +#pragma warning (disable:4996) +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#else +#include +#endif + +// Useful for shaders with error messages.. +std::string LineNumberString(const std::string &str); + +// Other simple string utilities. + +inline bool startsWith(const std::string &str, const std::string &what) { + if (str.size() < what.size()) + return false; + return str.substr(0, what.size()) == 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; +} + +// Only use on strings where you're only concerned about ASCII. +inline bool startsWithNoCase(const std::string &str, const std::string &what) { + if (str.size() < what.size()) + return false; + return strncasecmp(str.c_str(), what.c_str(), what.size()) == 0; +} + +inline bool endsWithNoCase(const std::string &str, const std::string &what) { + if (str.size() < what.size()) + return false; + const size_t offset = str.size() - what.size(); + return strncasecmp(str.c_str() + offset, what.c_str(), what.size()) == 0; +} + +void DataToHexString(const uint8_t *data, size_t size, std::string *output); +void DataToHexString(const char* prefix, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output); + +std::string StringFromFormat(const char* format, ...); +std::string StringFromInt(int value); + +std::string StripSpaces(const std::string &s); +std::string StripQuotes(const std::string &s); + +void SplitString(const std::string& str, const char delim, std::vector& output); + +void GetQuotedStrings(const std::string& str, std::vector& output); + +std::string ReplaceAll(std::string input, const std::string& src, const std::string& dest); + +void SkipSpace(const char **ptr); void truncate_cpy(char *dest, size_t destSize, const char *src); template diff --git a/Core/Debugger/WebSocket/DisasmSubscriber.cpp b/Core/Debugger/WebSocket/DisasmSubscriber.cpp index 6d2f76d746..e84596b849 100644 --- a/Core/Debugger/WebSocket/DisasmSubscriber.cpp +++ b/Core/Debugger/WebSocket/DisasmSubscriber.cpp @@ -17,8 +17,10 @@ #include #include -#include "base/stringutil.h" + #include "util/text/utf8.h" + +#include "Common/StringUtils.h" #include "Core/Debugger/Breakpoints.h" #include "Core/Debugger/DisassemblyManager.h" #include "Core/Debugger/WebSocket/DisasmSubscriber.h" diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp index ae65e692fa..cbdb5df051 100644 --- a/Core/Debugger/WebSocket/HLESubscriber.cpp +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -15,7 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "base/stringutil.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/Core.h" #include "Core/Debugger/DisassemblyManager.h" diff --git a/Core/Debugger/WebSocket/SteppingSubscriber.cpp b/Core/Debugger/WebSocket/SteppingSubscriber.cpp index d3422b48f9..19c545de86 100644 --- a/Core/Debugger/WebSocket/SteppingSubscriber.cpp +++ b/Core/Debugger/WebSocket/SteppingSubscriber.cpp @@ -15,7 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "base/stringutil.h" +#include "Common/StringUtils.h" #include "Core/Debugger/Breakpoints.h" #include "Core/Debugger/DisassemblyManager.h" #include "Core/Debugger/WebSocket/SteppingSubscriber.h" diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 23e1303780..8328ae34f5 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -21,13 +21,13 @@ #include -#include "base/stringutil.h" #include "i18n/i18n.h" #include "thread/threadutil.h" #include "Common/FileUtil.h" #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" +#include "Common/StringUtils.h" #include "Core/FileSystems/MetaFileSystem.h" #include "Core/Util/PPGeDraw.h" #include "Core/HLE/sceCtrl.h" diff --git a/Core/FileLoaders/HTTPFileLoader.cpp b/Core/FileLoaders/HTTPFileLoader.cpp index 7d710dbe52..094e78e639 100644 --- a/Core/FileLoaders/HTTPFileLoader.cpp +++ b/Core/FileLoaders/HTTPFileLoader.cpp @@ -17,8 +17,8 @@ #include -#include "base/stringutil.h" #include "Common/Common.h" +#include "Common/StringUtils.h" #include "Core/FileLoaders/HTTPFileLoader.h" HTTPFileLoader::HTTPFileLoader(const std::string &filename) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 45dc902f04..ccb4365323 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -19,13 +19,14 @@ #include #include -#include "base/stringutil.h" + #include "file/free.h" #include "file/zip_read.h" #include "i18n/i18n.h" #include "util/text/utf8.h" #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" +#include "Common/StringUtils.h" #include "Common/FileUtil.h" #include "Core/FileSystems/DirectoryFileSystem.h" #include "Core/FileSystems/ISOFileSystem.h" diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 34b3a9bc3c..601b01f166 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -21,7 +21,6 @@ #include "zlib.h" -#include "base/stringutil.h" #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" #include "Common/Serialize/SerializeSet.h" diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 6bd3d2d434..da89ff34bb 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -23,6 +23,7 @@ #include "Common/CommonTypes.h" #include "Common/LogManager.h" +#include "Common/StringUtils.h" #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" #include "Common/Serialize/SerializeList.h" diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index 97eca751ee..6054eed875 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -18,9 +18,9 @@ #include #include -#include "base/stringutil.h" #include "file/file_util.h" #include "Common/FileUtil.h" +#include "Common/StringUtils.h" #include "Core/FileLoaders/CachingFileLoader.h" #include "Core/FileLoaders/DiskCachingFileLoader.h" diff --git a/Core/Reporting.cpp b/Core/Reporting.cpp index 1829fd8a97..36bac97703 100644 --- a/Core/Reporting.cpp +++ b/Core/Reporting.cpp @@ -19,12 +19,16 @@ #include #include #include +#include +#include +#include #include "Core/Reporting.h" #include "Common/CPUDetect.h" #include "Common/FileUtil.h" #include "Common/Serialize/SerializeFuncs.h" +#include "Common/StringUtils.h" #include "Core/Core.h" #include "Core/CoreTiming.h" #include "Core/Config.h" @@ -44,15 +48,10 @@ #include "net/resolve.h" #include "net/url.h" -#include "base/stringutil.h" #include "base/buffer.h" #include "thread/threadutil.h" #include "file/zip_read.h" -#include -#include -#include - namespace Reporting { const int DEFAULT_PORT = 80; diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index c5a960c69d..26c4a6f512 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -20,7 +20,6 @@ #include #include -#include "base/stringutil.h" #include "i18n/i18n.h" #include "thread/threadutil.h" #include "util/text/parsers.h" @@ -28,6 +27,7 @@ #include "Common/FileUtil.h" #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" +#include "Common/StringUtils.h" #include "Common/TimeUtil.h" #include "Core/SaveState.h" diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index 7cdb34c23a..32e49b0a6c 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -22,13 +22,14 @@ #endif #include -#include "base/stringutil.h" + #include "i18n/i18n.h" #include "ext/xxhash.h" #include "file/ini_file.h" #include "util/text/parsers.h" #include "Common/ColorConv.h" #include "Common/FileUtil.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/Host.h" #include "Core/System.h" diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 05484bd8af..c724c0b37e 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -18,7 +18,6 @@ #include #include "base/colorutil.h" -#include "base/stringutil.h" #include "file/vfs.h" #include "gfx/texture_atlas.h" #include "gfx_es2/draw_text.h" @@ -28,6 +27,7 @@ #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" +#include "Common/StringUtils.h" #include "Core/HDRemaster.h" #include "Core/Host.h" #include "GPU/ge_constants.h" diff --git a/Core/WebServer.cpp b/Core/WebServer.cpp index d00753a1d4..222ab247de 100644 --- a/Core/WebServer.cpp +++ b/Core/WebServer.cpp @@ -18,16 +18,16 @@ #include #include #include -#include -#include "base/stringutil.h" + #include "file/fd_util.h" #include "net/http_client.h" #include "net/http_server.h" #include "net/sinks.h" #include "thread/threadutil.h" +#include "Common/Log.h" #include "Common/FileUtil.h" #include "Common/TimeUtil.h" -#include "Common/Log.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/Debugger/WebSocket.h" #include "Core/WebServer.h" diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index d0d9ec8963..3a91e60695 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -27,6 +27,7 @@ #include "file/vfs.h" #include "gfx_es2/gpu_features.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "GPU/Common/PostShader.h" diff --git a/GPU/Common/ShaderTranslation.cpp b/GPU/Common/ShaderTranslation.cpp index e0b58908fc..c38d2420b1 100644 --- a/GPU/Common/ShaderTranslation.cpp +++ b/GPU/Common/ShaderTranslation.cpp @@ -35,8 +35,9 @@ #endif #include "base/basictypes.h" -#include "base/stringutil.h" #include "Common/Log.h" +#include "Common/StringUtils.h" + #include "GPU/Common/ShaderTranslation.h" #include "ext/glslang/SPIRV/GlslangToSpv.h" #include "thin3d/thin3d.h" diff --git a/GPU/D3D11/D3D11Util.cpp b/GPU/D3D11/D3D11Util.cpp index add974eb75..27fcc093dd 100644 --- a/GPU/D3D11/D3D11Util.cpp +++ b/GPU/D3D11/D3D11Util.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -12,10 +13,10 @@ #include "thin3d/d3d11_loader.h" #endif -#include "base/stringutil.h" - #include "Common/CommonFuncs.h" #include "Common/Log.h" +#include "Common/StringUtils.h" + #include "D3D11Util.h" static std::vector CompileShaderToBytecode(const char *code, size_t codeSize, const char *target, UINT flags) { @@ -126,7 +127,7 @@ void StockObjectsD3D11::Create(ID3D11Device *device) { sampler_desc.MinLOD = -FLT_MAX; sampler_desc.MaxLOD = FLT_MAX; sampler_desc.MipLODBias = 0.0f; - sampler_desc.MaxAnisotropy = 1.0f; + sampler_desc.MaxAnisotropy = 1; ASSERT_SUCCESS(device->CreateSamplerState(&sampler_desc, &samplerPoint2DWrap)); sampler_desc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; ASSERT_SUCCESS(device->CreateSamplerState(&sampler_desc, &samplerLinear2DWrap)); diff --git a/GPU/Debugger/Record.cpp b/GPU/Debugger/Record.cpp index 32455e3c1a..05ad3b2ff1 100644 --- a/GPU/Debugger/Record.cpp +++ b/GPU/Debugger/Record.cpp @@ -21,10 +21,12 @@ #include #include #include -#include "base/stringutil.h" + #include "Common/Common.h" #include "Common/FileUtil.h" #include "Common/Log.h" +#include "Common/StringUtils.h" + #include "Core/Core.h" #include "Core/ELF/ParamSFO.h" #include "Core/HLE/sceDisplay.h" diff --git a/GPU/Directx9/ShaderManagerDX9.cpp b/GPU/Directx9/ShaderManagerDX9.cpp index fd64cb4570..a7129030a3 100644 --- a/GPU/Directx9/ShaderManagerDX9.cpp +++ b/GPU/Directx9/ShaderManagerDX9.cpp @@ -23,7 +23,6 @@ #include #include "gfx/d3d9_shader.h" -#include "base/stringutil.h" #include "i18n/i18n.h" #include "math/lin/matrix4x4.h" #include "math/math_util.h" @@ -33,6 +32,8 @@ #include "Common/Common.h" #include "Common/Log.h" +#include "Common/StringUtils.h" + #include "Core/Config.h" #include "Core/Host.h" #include "Core/Reporting.h" diff --git a/GPU/Directx9/VertexShaderGeneratorDX9.cpp b/GPU/Directx9/VertexShaderGeneratorDX9.cpp index a0f29a985f..cdc3cdbff7 100644 --- a/GPU/Directx9/VertexShaderGeneratorDX9.cpp +++ b/GPU/Directx9/VertexShaderGeneratorDX9.cpp @@ -15,14 +15,14 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include +#include #include #if defined(_WIN32) && defined(_DEBUG) #include "Common/CommonWindows.h" #endif -#include "base/stringutil.h" +#include "Common/StringUtils.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" #include "Core/Config.h" diff --git a/GPU/GLES/VertexShaderGeneratorGLES.cpp b/GPU/GLES/VertexShaderGeneratorGLES.cpp index b2e57be7bf..c3f3a0b716 100644 --- a/GPU/GLES/VertexShaderGeneratorGLES.cpp +++ b/GPU/GLES/VertexShaderGeneratorGLES.cpp @@ -25,7 +25,7 @@ #include "Common/CommonWindows.h" #endif -#include "base/stringutil.h" +#include "Common/StringUtils.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" #include "Core/Config.h" diff --git a/GPU/Vulkan/ShaderManagerVulkan.cpp b/GPU/Vulkan/ShaderManagerVulkan.cpp index c3d937049f..a1ec302265 100644 --- a/GPU/Vulkan/ShaderManagerVulkan.cpp +++ b/GPU/Vulkan/ShaderManagerVulkan.cpp @@ -19,7 +19,6 @@ //#define SHADERLOG #endif -#include "base/stringutil.h" #include "math/lin/matrix4x4.h" #include "math/math_util.h" #include "math/dataconv.h" @@ -27,6 +26,7 @@ #include "thin3d/thin3d.h" #include "util/text/utf8.h" +#include "Common/StringUtils.h" #include "Common/Vulkan/VulkanContext.h" #include "Common/Vulkan/VulkanMemory.h" #include "Common/Log.h" diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 90c08512f5..d84827b698 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -27,6 +27,7 @@ #include "thin3d/VulkanRenderManager.h" #include "Common/ColorConv.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/Host.h" #include "Core/MemMap.h" diff --git a/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp b/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp index b63bac2c1d..ca732d23e9 100644 --- a/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp +++ b/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp @@ -25,7 +25,7 @@ #include "Common/CommonWindows.h" #endif -#include "base/stringutil.h" +#include "Common/StringUtils.h" #include "Common/Vulkan/VulkanLoader.h" #include "Core/Config.h" #include "GPU/ge_constants.h" diff --git a/GPU/Vulkan/VulkanUtil.cpp b/GPU/Vulkan/VulkanUtil.cpp index 6d59ba6a1a..0e52abc314 100644 --- a/GPU/Vulkan/VulkanUtil.cpp +++ b/GPU/Vulkan/VulkanUtil.cpp @@ -15,9 +15,8 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "base/basictypes.h" -#include "base/stringutil.h" #include "Common/Log.h" +#include "Common/StringUtils.h" #include "Common/Vulkan/VulkanContext.h" #include "GPU/Vulkan/VulkanUtil.h" diff --git a/UI/ComboKeyMappingScreen.cpp b/UI/ComboKeyMappingScreen.cpp index 8741168179..3ccc55c824 100644 --- a/UI/ComboKeyMappingScreen.cpp +++ b/UI/ComboKeyMappingScreen.cpp @@ -15,10 +15,6 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "TouchControlVisibilityScreen.h" -#include "UI/ComboKeyMappingScreen.h" - -#include "Core/Config.h" #include "i18n/i18n.h" #include "base/colorutil.h" #include "base/display.h" @@ -26,12 +22,16 @@ #include "gfx_es2/draw_buffer.h" #include "gfx/texture_atlas.h" #include "math/curves.h" -#include "base/stringutil.h" #include "ui/ui_context.h" #include "ui/view.h" #include "ui/viewgroup.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" +#include "Core/Config.h" + +#include "TouchControlVisibilityScreen.h" +#include "UI/ComboKeyMappingScreen.h" void ComboKeyScreen::CreateViews() { using namespace UI; diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index a5c040d029..b0d2bfc5f2 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -15,13 +15,13 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include "base/stringutil.h" #include "ext/xxhash.h" #include "i18n/i18n.h" #include "ui/ui.h" #include "util/text/utf8.h" #include "Common/FileUtil.h" +#include "Common/StringUtils.h" #include "Core/Core.h" #include "Core/Config.h" #include "Core/CwCheat.h" diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 86d6c9b71a..022f157ed6 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -19,7 +19,6 @@ #include "ppsspp_config.h" #include "base/display.h" -#include "base/stringutil.h" #include "gfx_es2/gpu_features.h" #include "i18n/i18n.h" #include "ui/ui_context.h" @@ -30,6 +29,7 @@ #include "Common/LogManager.h" #include "Common/CPUDetect.h" +#include "Common/StringUtils.h" #include "Core/MemMap.h" #include "Core/Config.h" diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index a88130091a..807448c8ad 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -22,7 +22,6 @@ #include #include -#include "base/stringutil.h" #include "file/file_util.h" #include "file/zip_read.h" #include "thin3d/thin3d.h" diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 229cb4e8c9..5d8d04ff1c 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -22,8 +22,6 @@ #include "base/display.h" // Only to check screen aspect ratio with pixel_yres/pixel_xres #include "base/colorutil.h" -#include "base/stringutil.h" -#include "Common/TimeUtil.h" #include "math/curves.h" #include "net/resolve.h" #include "gfx_es2/gpu_features.h" @@ -54,6 +52,8 @@ #include "Common/KeyMap.h" #include "Common/FileUtil.h" #include "Common/OSVersion.h" +#include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/ConfigValues.h" #include "Core/Host.h" diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index ca03869cd8..319c8b860e 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -25,7 +25,6 @@ #include "gfx/texture_atlas.h" #include "gfx_es2/draw_buffer.h" #include "math/curves.h" -#include "base/stringutil.h" #include "ui/root.h" #include "ui/ui_context.h" #include "ui/view.h" @@ -34,6 +33,7 @@ #include "Common/FileUtil.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #include "Core/System.h" #include "Core/Host.h" #include "Core/Reporting.h" diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index b783140809..57cfbea75d 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -44,8 +44,6 @@ #endif #include "base/display.h" -#include "base/stringutil.h" -#include "Common/TimeUtil.h" #include "base/NativeApp.h" #include "file/vfs.h" #include "file/zip_read.h" @@ -71,6 +69,8 @@ #include "Common/CPUDetect.h" #include "Common/FileUtil.h" +#include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #include "Common/KeyMap.h" #include "Common/LogManager.h" #include "Common/MemArena.h" diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index df694192f4..ee36bba3ba 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -17,7 +17,7 @@ #include #include -#include "base/stringutil.h" + #include "i18n/i18n.h" #include "gfx_es2/draw_buffer.h" #include "ui/view.h" @@ -26,6 +26,8 @@ #include "ui/ui_screen.h" #include "thin3d/thin3d.h" +#include "Common/StringUtils.h" + #include "Core/Reporting.h" #include "Core/SaveState.h" #include "Core/System.h" diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index e52fa68505..e0c5a4c990 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -25,7 +25,6 @@ #include #endif -#include "base/stringutil.h" #include "file/path.h" // TODO: For text align flags, probably shouldn't be in gfx_es2/... #include "gfx_es2/draw_buffer.h" @@ -34,8 +33,10 @@ #include "net/http_client.h" #include "net/resolve.h" #include "net/url.h" + #include "Common/Common.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/WebServer.h" #include "UI/RemoteISOScreen.h" diff --git a/UI/ReportScreen.cpp b/UI/ReportScreen.cpp index f214ba9dfd..ae7a8909a9 100644 --- a/UI/ReportScreen.cpp +++ b/UI/ReportScreen.cpp @@ -18,7 +18,6 @@ #include #include "base/display.h" -#include "base/stringutil.h" // TODO: For text align flags, probably shouldn't be in gfx_es2/... #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" @@ -33,6 +32,7 @@ #include "Core/System.h" #include "Common/FileUtil.h" #include "Common/Log.h" +#include "Common/StringUtils.h" using namespace UI; diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index 45e951c419..9714b689a0 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -19,7 +19,6 @@ #include #include "base/colorutil.h" -#include "base/stringutil.h" #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" #include "math/curves.h" @@ -35,6 +34,7 @@ #include "Common/FileUtil.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #include "Core/Host.h" #include "Core/Config.h" #include "Core/Loaders.h" diff --git a/UWP/NativeUWP/NativeUWP.vcxproj b/UWP/NativeUWP/NativeUWP.vcxproj index 0d4f747f02..51fc5b92b4 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj +++ b/UWP/NativeUWP/NativeUWP.vcxproj @@ -387,7 +387,6 @@ - @@ -472,7 +471,6 @@ - diff --git a/UWP/NativeUWP/NativeUWP.vcxproj.filters b/UWP/NativeUWP/NativeUWP.vcxproj.filters index a424450ad6..add1237be7 100644 --- a/UWP/NativeUWP/NativeUWP.vcxproj.filters +++ b/UWP/NativeUWP/NativeUWP.vcxproj.filters @@ -73,9 +73,6 @@ base - - base - thin3d @@ -487,9 +484,6 @@ base - - base - thin3d diff --git a/Windows/Debugger/Debugger_Disasm.cpp b/Windows/Debugger/Debugger_Disasm.cpp index ecfaca8749..f5d80c6e77 100644 --- a/Windows/Debugger/Debugger_Disasm.cpp +++ b/Windows/Debugger/Debugger_Disasm.cpp @@ -24,10 +24,11 @@ #include "Core/CoreTiming.h" #include "Core/MIPS/MIPSAnalyst.h" -#include "base/stringutil.h" #include "util/text/utf8.h" #include "Common/CommonWindows.h" +#include "Common/StringUtils.h" + #include #include diff --git a/Windows/GEDebugger/GEDebugger.cpp b/Windows/GEDebugger/GEDebugger.cpp index 5fb0fcb72b..c22b00b554 100644 --- a/Windows/GEDebugger/GEDebugger.cpp +++ b/Windows/GEDebugger/GEDebugger.cpp @@ -20,9 +20,9 @@ #include #include -#include "base/stringutil.h" #include "util/text/parsers.h" #include "Common/ColorConv.h" +#include "Common/StringUtils.h" #include "Core/Config.h" #include "Core/Screenshot.h" #include "Windows/GEDebugger/GEDebugger.h" diff --git a/Windows/GPU/WindowsVulkanContext.cpp b/Windows/GPU/WindowsVulkanContext.cpp index 7b10b5e7c8..38b7623352 100644 --- a/Windows/GPU/WindowsVulkanContext.cpp +++ b/Windows/GPU/WindowsVulkanContext.cpp @@ -55,7 +55,6 @@ #include "Common/Vulkan/VulkanLoader.h" #include "Common/Vulkan/VulkanContext.h" -#include "base/stringutil.h" #include "thin3d/thin3d.h" #include "thin3d/thin3d_create.h" #include "thin3d/VulkanRenderManager.h" diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 78a60abf28..14fc10cdf8 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -34,8 +34,8 @@ #include "base/display.h" #include "base/NativeApp.h" -#include "base/stringutil.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #include "i18n/i18n.h" #include "input/input_state.h" #include "input/keycodes.h" diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index ab80ec4cea..d054c50741 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -7,7 +7,6 @@ #include "resource.h" -#include "base/stringutil.h" #include "i18n/i18n.h" #include "util/text/utf8.h" #include "base/NativeApp.h" @@ -19,6 +18,7 @@ #include "Common/ConsoleListener.h" #include "Common/OSVersion.h" #include "Common/Vulkan/VulkanLoader.h" +#include "Common/StringUtils.h" #if PPSSPP_API(ANY_GL) #include "GPU/GLES/TextureScalerGLES.h" #include "GPU/GLES/TextureCacheGLES.h" diff --git a/Windows/main.cpp b/Windows/main.cpp index bf2b74adcc..2fdfc565d8 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -32,7 +32,6 @@ #include #include "base/display.h" -#include "base/stringutil.h" #include "base/NativeApp.h" #include "file/vfs.h" #include "file/zip_read.h" @@ -51,6 +50,7 @@ #include "Common/LogManager.h" #include "Common/ConsoleListener.h" +#include "Common/StringUtils.h" #include "Commctrl.h" diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index bdd2891d30..bba710d3f0 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -50,7 +50,6 @@ struct JNIEnv {}; #endif #include "base/basictypes.h" -#include "base/stringutil.h" #include "base/display.h" #include "base/NativeApp.h" #include "thread/threadutil.h" @@ -67,7 +66,9 @@ struct JNIEnv {}; #include "Common/Log.h" #include "Common/GraphicsContext.h" +#include "Common/StringUtils.h" #include "Common/TimeUtil.h" + #include "AndroidGraphicsContext.h" #include "AndroidVulkanContext.h" #include "AndroidEGLContext.h" diff --git a/ext/native/Android.mk b/ext/native/Android.mk index a922490f88..fc41991fd9 100644 --- a/ext/native/Android.mk +++ b/ext/native/Android.mk @@ -10,7 +10,6 @@ LOCAL_SRC_FILES :=\ base/buffer.cpp \ base/display.cpp \ base/colorutil.cpp \ - base/stringutil.cpp \ data/base64.cpp \ data/compression.cpp \ ext/cityhash/city.cpp \ diff --git a/ext/native/base/basictypes.h b/ext/native/base/basictypes.h index 3334cea629..f2e53d2d1e 100644 --- a/ext/native/base/basictypes.h +++ b/ext/native/base/basictypes.h @@ -33,8 +33,6 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) #endif -inline uint8_t swap8(uint8_t _data) {return _data;} - // Just in case this has been defined by platform #undef swap16 #undef swap32 diff --git a/ext/native/base/stringutil.cpp b/ext/native/base/stringutil.cpp deleted file mode 100644 index 965c458040..0000000000 --- a/ext/native/base/stringutil.cpp +++ /dev/null @@ -1,198 +0,0 @@ -#include "ppsspp_config.h" -#ifdef _WIN32 -#include -#undef min -#undef max -#endif -#if PPSSPP_PLATFORM(SWITCH) -#define _GNU_SOURCE -#include -#endif -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "base/buffer.h" -#include "base/stringutil.h" - -std::string LineNumberString(const std::string &str) { - std::stringstream input(str); - std::stringstream output; - std::string line; - - int lineNumber = 1; - while (std::getline(input, line)) { - output << std::setw(4) << lineNumber++ << ": " << line << std::endl; - } - - return output.str(); -} - -void SkipSpace(const char **ptr) { - while (**ptr && isspace(**ptr)) { - (*ptr)++; - } -} - -void DataToHexString(const uint8_t *data, size_t size, std::string *output) { - Buffer buffer; - for (size_t i = 0; i < size; i++) { - if (i && !(i & 15)) - buffer.Printf("\n"); - buffer.Printf("%02x ", data[i]); - } - buffer.TakeAll(output); -} - -void DataToHexString(const char* prefix, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output) { - Buffer buffer; - size_t i = 0; - for (; i < size; i++) { - if (i && !(i & 15)) { - buffer.Printf(" "); - for (size_t j = i - 16; j < i; j++) { - buffer.Printf("%c", ((data[j] < 0x20) || (data[j] > 0x7e)) ? 0x2e : data[j]); - } - buffer.Printf("\n"); - } - if (!(i & 15)) - buffer.Printf("%s%08x ", prefix, startAddr + i); - buffer.Printf("%02x ", data[i]); - } - if (size & 15) { - size_t padded_size = ((size-1) | 15) + 1; - for (size_t j = size; j < padded_size; j++) { - buffer.Printf(" "); - } - buffer.Printf(" "); - for (size_t j = size & ~UINT64_C(0xF); j < size; j++) { - buffer.Printf("%c", ((data[j] < 0x20) || (data[j] > 0x7e)) ? 0x2e : data[j]); - } - } - buffer.TakeAll(output); -} - -std::string StringFromFormat(const char* format, ...) -{ - va_list args; - std::string temp = ""; -#ifdef _WIN32 - int required = 0; - - va_start(args, format); - required = _vscprintf(format, args); - // Using + 2 to be safe between MSVC versions. - // In MSVC 2015 and later, vsnprintf counts the trailing zero (per c++11.) - temp.resize(required + 2); - if (vsnprintf(&temp[0], required + 1, format, args) < 0) { - temp.resize(0); - } else { - temp.resize(required); - } - va_end(args); -#else - char *buf = nullptr; - - va_start(args, format); - if (vasprintf(&buf, format, args) < 0) - buf = nullptr; - va_end(args); - - if (buf != nullptr) { - temp = buf; - free(buf); - } -#endif - return temp; -} - -std::string StringFromInt(int value) -{ - char temp[16]; - sprintf(temp, "%i", value); - return temp; -} - -// Turns " hej " into "hej". Also handles tabs. -std::string StripSpaces(const std::string &str) -{ - const size_t s = str.find_first_not_of(" \t\r\n"); - - if (str.npos != s) - return str.substr(s, str.find_last_not_of(" \t\r\n") - s + 1); - else - return ""; -} - -// "\"hello\"" is turned to "hello" -// This one assumes that the string has already been space stripped in both -// ends, as done by StripSpaces above, for example. -std::string StripQuotes(const std::string& s) -{ - if (s.size() && '\"' == s[0] && '\"' == *s.rbegin()) - return s.substr(1, s.size() - 2); - else - return s; -} - -void SplitString(const std::string& str, const char delim, std::vector& output) -{ - size_t next = 0; - for (size_t pos = 0, len = str.length(); pos < len; ++pos) { - if (str[pos] == delim) { - output.push_back(str.substr(next, pos - next)); - // Skip the delimiter itself. - next = pos + 1; - } - } - - if (next == 0) { - output.push_back(str); - } else if (next < str.length()) { - output.push_back(str.substr(next)); - } -} - -void GetQuotedStrings(const std::string& str, std::vector& output) -{ - size_t next = 0; - bool even = 0; - for (size_t pos = 0, len = str.length(); pos < len; ++pos) { - if (str[pos] == '\"' || str[pos] == '\'') { - if (even) { - //quoted text - output.push_back(str.substr(next, pos - next)); - even = 0; - } else { - //non quoted text - even = 1; - } - // Skip the delimiter itself. - next = pos + 1; - } - } -} - -std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) -{ - size_t pos = 0; - - if (src == dest) - return result; - - while(1) - { - pos = result.find(src, pos); - if (pos == result.npos) - break; - result.replace(pos, src.size(), dest); - pos += dest.size(); - } - return result; -} diff --git a/ext/native/base/stringutil.h b/ext/native/base/stringutil.h deleted file mode 100644 index 0e293a0f43..0000000000 --- a/ext/native/base/stringutil.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include -#include - -#include "base/basictypes.h" - -#ifdef _MSC_VER -#pragma warning (disable:4996) -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#else -#include -#endif - -// Useful for shaders with error messages.. -std::string LineNumberString(const std::string &str); - -// Other simple string utilities. - -inline bool startsWith(const std::string &str, const std::string &what) { - if (str.size() < what.size()) - return false; - return str.substr(0, what.size()) == 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; -} - -// Only use on strings where you're only concerned about ASCII. -inline bool startsWithNoCase(const std::string &str, const std::string &what) { - if (str.size() < what.size()) - return false; - return strncasecmp(str.c_str(), what.c_str(), what.size()) == 0; -} - -inline bool endsWithNoCase(const std::string &str, const std::string &what) { - if (str.size() < what.size()) - return false; - const size_t offset = str.size() - what.size(); - return strncasecmp(str.c_str() + offset, what.c_str(), what.size()) == 0; -} - -void DataToHexString(const uint8_t *data, size_t size, std::string *output); -void DataToHexString(const char* prefix, uint32_t startAddr, const uint8_t* data, size_t size, std::string* output); - -std::string StringFromFormat(const char* format, ...); -std::string StringFromInt(int value); - -std::string StripSpaces(const std::string &s); -std::string StripQuotes(const std::string &s); - -void SplitString(const std::string& str, const char delim, std::vector& output); - -void GetQuotedStrings(const std::string& str, std::vector& output); - -std::string ReplaceAll(std::string input, const std::string& src, const std::string& dest); - -void SkipSpace(const char **ptr); diff --git a/ext/native/file/file_util.cpp b/ext/native/file/file_util.cpp index 7206c36e3c..9ef63d5462 100644 --- a/ext/native/file/file_util.cpp +++ b/ext/native/file/file_util.cpp @@ -19,10 +19,11 @@ #include #include "base/basictypes.h" -#include "base/stringutil.h" #include "file/file_util.h" #include "util/text/utf8.h" +#include "Common/StringUtils.h" + #if !defined(__linux__) && !defined(_WIN32) && !defined(__QNX__) #define stat64 stat #endif @@ -126,22 +127,6 @@ bool readFileToString(bool text_file, const char *filename, std::string &str) return true; } - -bool readDataFromFile(bool text_file, unsigned char* &data, const unsigned int size, const char *filename) -{ - FILE *f = openCFile(filename, text_file ? "r" : "rb"); - if (!f) - return false; - size_t len = (size_t)GetSize(f); - if(len < size) { - fclose(f); - return false; - } - data[fread(data, 1, size, f)] = 0; - fclose(f); - return true; -} - // Returns true if filename is a directory bool isDirectory(const std::string &filename) { FileInfo info; diff --git a/ext/native/file/file_util.h b/ext/native/file/file_util.h index b6c414139b..e194f3f2b2 100644 --- a/ext/native/file/file_util.h +++ b/ext/native/file/file_util.h @@ -12,7 +12,6 @@ bool writeStringToFile(bool text_file, const std::string &str, const char *filen bool readFileToString(bool text_file, const char *filename, std::string &str); bool writeDataToFile(bool text_file, const void* data, const unsigned int size, const char *filename); -bool readDataFromFile(bool text_file, unsigned char* &data, const unsigned int size, const char *filename); // Beginnings of a directory utility system. TODO: Improve. diff --git a/ext/native/file/ini_file.cpp b/ext/native/file/ini_file.cpp index c4c1b7934e..b6dcf0d977 100644 --- a/ext/native/file/ini_file.cpp +++ b/ext/native/file/ini_file.cpp @@ -16,7 +16,6 @@ #include #include -#include "base/stringutil.h" #include "file/ini_file.h" #include "file/vfs.h" #include "util/text/parsers.h" @@ -25,6 +24,8 @@ #include "util/text/utf8.h" #endif +#include "Common/StringUtils.h" + static bool ParseLineKey(const std::string &line, size_t &pos, std::string *keyOut) { std::string key = ""; @@ -164,6 +165,22 @@ std::string* Section::GetLine(const char* key, std::string* valueOut, std::strin return 0; } +void Section::Set(const char* key, uint32_t newValue) { + Set(key, StringFromFormat("0x%08x", newValue).c_str()); +} + +void Section::Set(const char* key, float newValue) { + Set(key, StringFromFormat("%f", newValue).c_str()); +} + +void Section::Set(const char* key, double newValue) { + Set(key, StringFromFormat("%f", newValue).c_str()); +} + +void Section::Set(const char* key, int newValue) { + Set(key, StringFromInt(newValue).c_str()); +} + void Section::Set(const char* key, const char* newValue) { std::string value, commented; diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index 4c2b65ed4b..5d65045033 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -8,7 +8,6 @@ #include #include #include -#include "base/stringutil.h" class Section { @@ -34,21 +33,13 @@ public: } bool Get(const char* key, std::string* value, const char* defaultValue); - void Set(const char* key, uint32_t newValue) { - Set(key, StringFromFormat("0x%08x", newValue).c_str()); - } - void Set(const char* key, float newValue) { - Set(key, StringFromFormat("%f", newValue).c_str()); - } + void Set(const char* key, uint32_t newValue); + void Set(const char* key, float newValue); void Set(const char* key, const float newValue, const float defaultValue); - void Set(const char* key, double newValue) { - Set(key, StringFromFormat("%f", newValue).c_str()); - } + void Set(const char* key, double newValue); void Set(const char* key, int newValue, int defaultValue); - void Set(const char* key, int newValue) { - Set(key, StringFromInt(newValue).c_str()); - } + void Set(const char* key, int newValue); void Set(const char* key, bool newValue, bool defaultValue); void Set(const char* key, bool newValue) { diff --git a/ext/native/file/path.cpp b/ext/native/file/path.cpp index 8025878c02..5be7b326c4 100644 --- a/ext/native/file/path.cpp +++ b/ext/native/file/path.cpp @@ -1,8 +1,10 @@ #include #include #include -#include "base/stringutil.h" + +#include "Common/StringUtils.h" #include "Common/TimeUtil.h" + #include "file/path.h" #include "net/http_client.h" #include "net/url.h" diff --git a/ext/native/gfx_es2/draw_buffer.cpp b/ext/native/gfx_es2/draw_buffer.cpp index da23c142cb..12307755f8 100644 --- a/ext/native/gfx_es2/draw_buffer.cpp +++ b/ext/native/gfx_es2/draw_buffer.cpp @@ -4,7 +4,6 @@ #include #include "base/display.h" -#include "base/stringutil.h" #include "math/math_util.h" #include "gfx/texture_atlas.h" #include "gfx/gl_debug_log.h" @@ -14,6 +13,7 @@ #include "util/text/wrap_text.h" #include "Common/Log.h" +#include "Common/StringUtils.h" enum { // Enough? diff --git a/ext/native/gfx_es2/draw_text.cpp b/ext/native/gfx_es2/draw_text.cpp index a205fbca61..581ea31274 100644 --- a/ext/native/gfx_es2/draw_text.cpp +++ b/ext/native/gfx_es2/draw_text.cpp @@ -1,5 +1,4 @@ #include "base/display.h" -#include "base/stringutil.h" #include "thin3d/thin3d.h" #include "util/hash/hash.h" #include "util/text/wrap_text.h" diff --git a/ext/native/gfx_es2/draw_text_android.cpp b/ext/native/gfx_es2/draw_text_android.cpp index 34e4295bd3..dc1ec66f8a 100644 --- a/ext/native/gfx_es2/draw_text_android.cpp +++ b/ext/native/gfx_es2/draw_text_android.cpp @@ -1,5 +1,4 @@ #include "base/display.h" -#include "base/stringutil.h" #include "thin3d/thin3d.h" #include "util/hash/hash.h" #include "util/text/wrap_text.h" diff --git a/ext/native/gfx_es2/draw_text_qt.cpp b/ext/native/gfx_es2/draw_text_qt.cpp index 39b4ac95eb..877e218ce7 100644 --- a/ext/native/gfx_es2/draw_text_qt.cpp +++ b/ext/native/gfx_es2/draw_text_qt.cpp @@ -1,5 +1,4 @@ #include "base/display.h" -#include "base/stringutil.h" #include "thin3d/thin3d.h" #include "util/hash/hash.h" #include "util/text/wrap_text.h" diff --git a/ext/native/gfx_es2/draw_text_uwp.cpp b/ext/native/gfx_es2/draw_text_uwp.cpp index 0e741b0077..b58af57ae2 100644 --- a/ext/native/gfx_es2/draw_text_uwp.cpp +++ b/ext/native/gfx_es2/draw_text_uwp.cpp @@ -1,5 +1,4 @@ #include "base/display.h" -#include "base/stringutil.h" #include "thin3d/thin3d.h" #include "util/hash/hash.h" #include "util/text/wrap_text.h" diff --git a/ext/native/gfx_es2/draw_text_win.cpp b/ext/native/gfx_es2/draw_text_win.cpp index 1d08616131..48315e5152 100644 --- a/ext/native/gfx_es2/draw_text_win.cpp +++ b/ext/native/gfx_es2/draw_text_win.cpp @@ -1,5 +1,4 @@ #include "base/display.h" -#include "base/stringutil.h" #include "thin3d/thin3d.h" #include "util/hash/hash.h" #include "util/text/wrap_text.h" @@ -8,6 +7,7 @@ #include "gfx_es2/draw_text_win.h" #include "Common/Log.h" +#include "Common/StringUtils.h" #if defined(_WIN32) && !defined(USING_QT_UI) && !PPSSPP_PLATFORM(UWP) diff --git a/ext/native/gfx_es2/gpu_features.cpp b/ext/native/gfx_es2/gpu_features.cpp index 930a489aae..f8b29909f3 100644 --- a/ext/native/gfx_es2/gpu_features.cpp +++ b/ext/native/gfx_es2/gpu_features.cpp @@ -3,7 +3,7 @@ #include #include -#include "base/stringutil.h" +#include "Common/StringUtils.h" #if PPSSPP_API(ANY_GL) #include "gfx/gl_common.h" diff --git a/ext/native/i18n/i18n.cpp b/ext/native/i18n/i18n.cpp index bbafbd9534..72ec1f949f 100644 --- a/ext/native/i18n/i18n.cpp +++ b/ext/native/i18n/i18n.cpp @@ -1,8 +1,9 @@ -#include "base/stringutil.h" #include "i18n/i18n.h" #include "file/ini_file.h" #include "file/vfs.h" +#include "Common/StringUtils.h" + I18NRepo i18nrepo; I18NRepo::~I18NRepo() { diff --git a/ext/native/native.vcxproj b/ext/native/native.vcxproj index b6653404d0..caee297bd3 100644 --- a/ext/native/native.vcxproj +++ b/ext/native/native.vcxproj @@ -387,7 +387,6 @@ - @@ -509,7 +508,6 @@ true true - diff --git a/ext/native/native.vcxproj.filters b/ext/native/native.vcxproj.filters index d4ce209515..0c847988b1 100644 --- a/ext/native/native.vcxproj.filters +++ b/ext/native/native.vcxproj.filters @@ -80,9 +80,6 @@ input - - base - ext @@ -412,9 +409,6 @@ file - - base - net diff --git a/ext/native/net/http_client.cpp b/ext/native/net/http_client.cpp index a8658b2ad2..4169c97123 100644 --- a/ext/native/net/http_client.cpp +++ b/ext/native/net/http_client.cpp @@ -1,5 +1,7 @@ #include "net/http_client.h" + #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" #ifndef _WIN32 #include @@ -19,7 +21,6 @@ #include #include "base/buffer.h" -#include "base/stringutil.h" #include "data/compression.h" #include "file/fd_util.h" #include "net/resolve.h" diff --git a/ext/native/net/http_headers.cpp b/ext/native/net/http_headers.cpp index e568c7c5c8..ca370dad9c 100644 --- a/ext/native/net/http_headers.cpp +++ b/ext/native/net/http_headers.cpp @@ -4,11 +4,11 @@ #include #include -#include "base/stringutil.h" #include "file/fd_util.h" #include "net/sinks.h" #include "Common/Log.h" +#include "Common/StringUtils.h" namespace http { diff --git a/ext/native/net/url.cpp b/ext/native/net/url.cpp index 943ed4e3eb..b3aa5ff25d 100644 --- a/ext/native/net/url.cpp +++ b/ext/native/net/url.cpp @@ -1,7 +1,7 @@ -#include "base/stringutil.h" #include "net/url.h" #include "Common/Log.h" +#include "Common/StringUtils.h" const char *UrlEncoder::unreservedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~"; const char *UrlEncoder::hexChars = "0123456789ABCDEF"; diff --git a/ext/native/net/websocket_server.cpp b/ext/native/net/websocket_server.cpp index c45b266222..b769219f9c 100644 --- a/ext/native/net/websocket_server.cpp +++ b/ext/native/net/websocket_server.cpp @@ -15,7 +15,6 @@ #include #endif -#include "base/stringutil.h" #include "data/base64.h" #include "net/http_server.h" #include "net/sinks.h" @@ -23,6 +22,7 @@ #include "Common/Crypto/sha1.h" #include "Common/Log.h" +#include "Common/StringUtils.h" static const char *const WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; diff --git a/ext/native/thin3d/GLQueueRunner.cpp b/ext/native/thin3d/GLQueueRunner.cpp index c5da0e4c21..aec9acb5d1 100644 --- a/ext/native/thin3d/GLQueueRunner.cpp +++ b/ext/native/thin3d/GLQueueRunner.cpp @@ -1,6 +1,5 @@ #include -#include "base/stringutil.h" #include "gfx/gl_common.h" #include "gfx/gl_debug_log.h" #include "gfx_es2/gpu_features.h" @@ -10,6 +9,7 @@ #include "Common/Log.h" #include "Common/MemoryUtil.h" +#include "Common/StringUtils.h" #include "Core/Reporting.h" #include "GLQueueRunner.h" diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index 825a437681..e929b89018 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -4,6 +4,7 @@ #include #include "Common/Log.h" +#include "Common/StringUtils.h" #include "Common/Vulkan/VulkanContext.h" #include "thin3d/VulkanRenderManager.h" diff --git a/ext/native/thin3d/VulkanRenderManager.h b/ext/native/thin3d/VulkanRenderManager.h index 50657051ef..57b1e78ec7 100644 --- a/ext/native/thin3d/VulkanRenderManager.h +++ b/ext/native/thin3d/VulkanRenderManager.h @@ -11,7 +11,6 @@ #include #include "base/display.h" -#include "base/stringutil.h" #include "Common/Vulkan/VulkanContext.h" #include "math/dataconv.h" #include "math/math_util.h" diff --git a/ext/native/thin3d/thin3d_vulkan.cpp b/ext/native/thin3d/thin3d_vulkan.cpp index 3308c7f657..855f80c7c8 100644 --- a/ext/native/thin3d/thin3d_vulkan.cpp +++ b/ext/native/thin3d/thin3d_vulkan.cpp @@ -21,7 +21,6 @@ #include #include "base/display.h" -#include "base/stringutil.h" #include "image/zim_load.h" #include "math/lin/matrix4x4.h" #include "math/dataconv.h" @@ -29,6 +28,7 @@ #include "thin3d/VulkanRenderManager.h" #include "Common/Log.h" +#include "Common/StringUtils.h" #include "Common/Vulkan/VulkanContext.h" #include "Common/Vulkan/VulkanImage.h" #include "Common/Vulkan/VulkanMemory.h" diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index ca36957b62..e46344a41a 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -3,7 +3,6 @@ #include #include "base/display.h" -#include "base/stringutil.h" #include "input/input_state.h" #include "input/keycodes.h" #include "math/curves.h" @@ -15,6 +14,7 @@ #include "gfx_es2/draw_buffer.h" #include "Common/Log.h" +#include "Common/StringUtils.h" static const bool ClickDebug = false; diff --git a/ext/native/ui/view.cpp b/ext/native/ui/view.cpp index b8e62a5cce..ce79dfc516 100644 --- a/ext/native/ui/view.cpp +++ b/ext/native/ui/view.cpp @@ -1,7 +1,6 @@ #include #include -#include "base/stringutil.h" #include "input/input_state.h" #include "input/keycodes.h" #include "gfx_es2/draw_buffer.h" @@ -16,6 +15,7 @@ #include "base/NativeApp.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" namespace UI { diff --git a/ext/native/ui/viewgroup.cpp b/ext/native/ui/viewgroup.cpp index cd3221f790..ecec7a1019 100644 --- a/ext/native/ui/viewgroup.cpp +++ b/ext/native/ui/viewgroup.cpp @@ -3,7 +3,6 @@ #include #include -#include "base/stringutil.h" #include "input/keycodes.h" #include "math/curves.h" #include "ui/ui_context.h" @@ -15,6 +14,7 @@ #include "Common/Log.h" #include "Common/TimeUtil.h" +#include "Common/StringUtils.h" namespace UI { diff --git a/ext/native/util/text/parsers.cpp b/ext/native/util/text/parsers.cpp index e762ec4232..f36f3ff33d 100644 --- a/ext/native/util/text/parsers.cpp +++ b/ext/native/util/text/parsers.cpp @@ -2,9 +2,10 @@ #include #include -#include "base/stringutil.h" #include "util/text/parsers.h" +#include "Common/StringUtils.h" + bool Version::ParseVersionString(std::string str) { if (str.empty()) return false; diff --git a/libretro/Makefile.common b/libretro/Makefile.common index 87fc689e03..eb0472bcbb 100644 --- a/libretro/Makefile.common +++ b/libretro/Makefile.common @@ -217,7 +217,6 @@ SOURCES_CXX += \ $(EXTDIR)/native/base/buffer.cpp \ $(EXTDIR)/native/base/colorutil.cpp \ $(EXTDIR)/native/base/display.cpp \ - $(EXTDIR)/native/base/stringutil.cpp \ $(EXTDIR)/native/data/compression.cpp \ $(EXTDIR)/native/json/json_reader.cpp \ $(EXTDIR)/glslang/OGLCompilersDLL/InitializeDll.cpp \