mirror of
https://github.com/vimpunk/mio.git
synced 2025-12-06 08:46:51 +08:00
Avoid multiply defined s_2_ws linker error
+ use std::wstring directly without intermediate std::vector in `s_2_ws` fixes #87
This commit is contained in:
parent
3f86a95c07
commit
fd9dc4be35
@ -52,14 +52,17 @@ inline DWORD int64_low(int64_t n) noexcept
|
|||||||
return n & 0xffffffff;
|
return n & 0xffffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring s_2_ws(const std::string& s)
|
inline std::wstring s_2_ws(const std::string& s)
|
||||||
{
|
{
|
||||||
if (s.empty())
|
std::wstring ret;
|
||||||
return{};
|
if (!s.empty())
|
||||||
const auto s_length = static_cast<int>(s.length());
|
{
|
||||||
auto buf = std::vector<wchar_t>(s_length);
|
ret.resize(s.size());
|
||||||
const auto wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s_length, buf.data(), s_length);
|
int wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(),
|
||||||
return std::wstring(buf.data(), wide_char_count);
|
static_cast<int>(s.size()), &ret[0], static_cast<int>(s.size()));
|
||||||
|
ret.resize(wide_char_count);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<
|
template<
|
||||||
|
|||||||
@ -794,14 +794,17 @@ inline DWORD int64_low(int64_t n) noexcept
|
|||||||
return n & 0xffffffff;
|
return n & 0xffffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring s_2_ws(const std::string& s)
|
inline std::wstring s_2_ws(const std::string& s)
|
||||||
{
|
{
|
||||||
if (s.empty())
|
std::wstring ret;
|
||||||
return{};
|
if (!s.empty())
|
||||||
const auto s_length = static_cast<int>(s.length());
|
{
|
||||||
auto buf = std::vector<wchar_t>(s_length);
|
ret.resize(s.size());
|
||||||
const auto wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), s_length, buf.data(), s_length);
|
int wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(),
|
||||||
return std::wstring(buf.data(), wide_char_count);
|
static_cast<int>(s.size()), &ret[0], static_cast<int>(s.size()));
|
||||||
|
ret.resize(wide_char_count);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<
|
template<
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user