Skip to content

Commit

Permalink
Merge pull request vimpunk#88 from pps83/master-fix-linker-s_2_ws
Browse files Browse the repository at this point in the history
Avoid multiply defined `s_2_ws` linker error
  • Loading branch information
vimpunk authored Mar 3, 2023
2 parents 3f86a95 + fd9dc4b commit 8b6b7d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 10 additions & 7 deletions include/mio/detail/mmap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ inline DWORD int64_low(int64_t n) noexcept
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())
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(), s_length, buf.data(), s_length);
return std::wstring(buf.data(), wide_char_count);
std::wstring ret;
if (!s.empty())
{
ret.resize(s.size());
int wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(),
static_cast<int>(s.size()), &ret[0], static_cast<int>(s.size()));
ret.resize(wide_char_count);
}
return ret;
}

template<
Expand Down
17 changes: 10 additions & 7 deletions single_include/mio/mio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,14 +794,17 @@ inline DWORD int64_low(int64_t n) noexcept
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())
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(), s_length, buf.data(), s_length);
return std::wstring(buf.data(), wide_char_count);
std::wstring ret;
if (!s.empty())
{
ret.resize(s.size());
int wide_char_count = MultiByteToWideChar(CP_UTF8, 0, s.c_str(),
static_cast<int>(s.size()), &ret[0], static_cast<int>(s.size()));
ret.resize(wide_char_count);
}
return ret;
}

template<
Expand Down

0 comments on commit 8b6b7d8

Please sign in to comment.