Adding support of UTF8 file name processing in mio on windows

Contributing back changes from app.
This commit is contained in:
shiagarw 2020-12-20 23:49:18 +05:30
parent 0a2b6cbd88
commit 72aa534b81
2 changed files with 22 additions and 2 deletions

View File

@ -68,13 +68,23 @@ template<
0); 0);
} }
std::wstring s_2_ws(const std::string& s)
{
if (s.empty())
return{};
const auto s_length = static_cast<int>(s.length());
auto buf = std::vector<wchar_t>(s_length);
const auto wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), sLength, buf.data(), s_length);
return std::wstring(buf.data(), wide_char_count);
}
template<typename String> template<typename String>
typename std::enable_if< typename std::enable_if<
std::is_same<typename char_type<String>::type, wchar_t>::value, std::is_same<typename char_type<String>::type, wchar_t>::value,
file_handle_type file_handle_type
>::type open_file_helper(const String& path, const access_mode mode) >::type open_file_helper(const String& path, const access_mode mode)
{ {
return ::CreateFileW(c_str(path), return ::CreateFileW(s_2_ws(path).c_str(),
mode == access_mode::read ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, mode == access_mode::read ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
0, 0,

View File

@ -810,13 +810,23 @@ template<
0); 0);
} }
std::wstring s_2_ws(const std::string& s)
{
if (s.empty())
return{};
const auto s_length = static_cast<int>(s.length());
auto buf = std::vector<wchar_t>(s_length);
const auto wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), sLength, buf.data(), s_length);
return std::wstring(buf.data(), wide_char_count);
}
template<typename String> template<typename String>
typename std::enable_if< typename std::enable_if<
std::is_same<typename char_type<String>::type, wchar_t>::value, std::is_same<typename char_type<String>::type, wchar_t>::value,
file_handle_type file_handle_type
>::type open_file_helper(const String& path, const access_mode mode) >::type open_file_helper(const String& path, const access_mode mode)
{ {
return ::CreateFileW(c_str(path), return ::CreateFileW(s_2_ws(path).c_str(),
mode == access_mode::read ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, mode == access_mode::read ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
0, 0,