From e487ffe1671ba807528d4039ef66f8f8f7eeb853 Mon Sep 17 00:00:00 2001 From: auth12 <67507608+auth12@users.noreply.github.com> Date: Fri, 24 Jul 2020 10:56:14 -0700 Subject: Injection process changes and server improvements. --- client/src/util/util.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'client/src/util/util.cpp') diff --git a/client/src/util/util.cpp b/client/src/util/util.cpp index 3dba550..b79f6cd 100644 --- a/client/src/util/util.cpp +++ b/client/src/util/util.cpp @@ -7,45 +7,37 @@ std::unordered_map util::loaded_modules; std::string util::wide_to_multibyte(const std::wstring& str) { std::string ret; - int32_t str_len; + size_t str_len; // check if not empty str if (str.empty()) return{}; // count size - str_len = WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t)str.size(), 0, 0, 0, 0); + str_len = WideCharToMultiByte(CP_UTF8, 0, &str[0], str.size(), 0, 0, 0, 0); // setup return value ret = std::string(str_len, 0); // final conversion - WideCharToMultiByte(CP_UTF8, 0, &str[0], (int32_t)str.size(), &ret[0], str_len, 0, 0); + WideCharToMultiByte(CP_UTF8, 0, &str[0], str.size(), &ret[0], str_len, 0, 0); return ret; } -std::wstring util::multibyte_to_wide(const std::string &str) { - std::wstring ret; - int32_t size; - wchar_t *wstr; - const char *buf = str.c_str(); +std::wstring util::multibyte_to_wide(const std::string& str) { + size_t size; + std::wstring out; // get size - size = MultiByteToWideChar(CP_UTF8, 0, buf, int32_t(strlen(buf) + 1), 0, 0); + size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size() + 1, 0, 0); - // alloc new wchars - wstr = new wchar_t[size]; + out.resize(size); // finally convert - MultiByteToWideChar(CP_UTF8, 0, buf, int32_t(strlen(buf) + 1), wstr, size); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size() + 1, &out[0], size); - // construct return string - ret = std::wstring(wstr); - - // cleanup - delete[] wstr; - return ret; + return out; } -- cgit v1.2.3