Fix string conversion

This commit is contained in:
LAGonauta 2021-02-23 07:04:43 -03:00
parent 1d1b00222f
commit 7fd918f32d
2 changed files with 2 additions and 12 deletions

View file

@ -3,18 +3,6 @@
#include "converter.hpp"
// Convert a wide Unicode string to an UTF8 string
std::string wstr_to_str(const std::wstring_view wstr)
{
if(wstr.empty())
{
return std::string();
}
int final_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr);
std::string strTo(final_size, 0);
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), strTo.data(), final_size, nullptr, nullptr);
return strTo;
}
char* wsview_to_char(const std::wstring_view wstr)
{
if(wstr.empty())

View file

@ -10,6 +10,7 @@ std::optional<std::wstring> GetCurrentModulePath()
auto charWritten = GetModuleFileName(nullptr, exePath.data(), exePath.size());
if (charWritten > 0)
{
exePath.resize(charWritten);
return exePath;
}
return std::nullopt;
@ -21,6 +22,7 @@ std::optional<std::wstring> GetShortcutPath()
auto charWritten = GetEnvironmentVariable(L"APPDATA", shortcutPath.data(), shortcutPath.size());
if (charWritten > 0)
{
shortcutPath.resize(charWritten);
return shortcutPath;
}
return std::nullopt;