From 329b58c8cd647ae089ba8e953ea1a9f01ae0e673 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 13 Jan 2024 15:42:49 +0100 Subject: [PATCH] fs: remove duplicate to_utf8 function --- Utilities/File.cpp | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index a766156e8a..873c53debc 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -1,6 +1,7 @@ #include "File.h" #include "mutex.h" #include "StrFmt.h" +#include "StrUtil.h" #include "Crypto/sha1.h" #include @@ -49,23 +50,6 @@ static std::unique_ptr to_wchar(const std::string& source) return buffer; } -static void to_utf8(std::string& out, const wchar_t* source) -{ - // String size - const usz length = std::wcslen(source); - - // Safe buffer size for max possible output length (including null terminator) - const int buf_size = narrow(length * 3 + 1); - - // Resize buffer - out.resize(buf_size - 1); - - const int result = WideCharToMultiByte(CP_UTF8, 0, source, static_cast(length) + 1, &out.front(), buf_size, nullptr, nullptr); - - // Fix the size - out.resize(ensure(result) - 1); -} - static time_t to_time(const ULARGE_INTEGER& ft) { return ft.QuadPart / 10000000ULL - 11644473600ULL; @@ -1789,7 +1773,7 @@ bool fs::dir::open(const std::string& path) { dir_entry info; - to_utf8(info.name, found.cFileName); + info.name = wchar_to_utf8(found.cFileName); info.is_directory = (found.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; info.is_writable = (found.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0; info.size = (static_cast(found.nFileSizeHigh) << 32) | static_cast(found.nFileSizeLow); @@ -1933,7 +1917,7 @@ const std::string& fs::get_config_dir() return dir; // empty } - to_utf8(dir, buf); // Convert to UTF-8 + dir = wchar_to_utf8(buf); std::replace(dir.begin(), dir.end(), '\\', '/'); @@ -2018,7 +2002,7 @@ const std::string& fs::get_temp_dir() return dir; // empty } - to_utf8(dir, buf); + dir = wchar_to_utf8(buf); #else // TODO dir = get_cache_dir();