diff --git a/ChangeLog b/ChangeLog index 8e4e117a7..9e3f38a87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * fix string encoding conversions on windows * take torrent_handle::query_pieces into account in torrent_handle::statue() * honor trackers responding with 410 * fixed merkle tree torrent creation bug diff --git a/include/libtorrent/escape_string.hpp b/include/libtorrent/escape_string.hpp index ed8912b8a..f3a918c1a 100644 --- a/include/libtorrent/escape_string.hpp +++ b/include/libtorrent/escape_string.hpp @@ -78,7 +78,7 @@ namespace libtorrent TORRENT_EXTRA_EXPORT std::string convert_from_wstring(std::wstring const& s); #endif -#if TORRENT_USE_ICONV || TORRENT_USE_LOCALE +#if TORRENT_USE_ICONV || TORRENT_USE_LOCALE || defined TORRENT_WINDOWS TORRENT_EXTRA_EXPORT std::string convert_to_native(std::string const& s); TORRENT_EXTRA_EXPORT std::string convert_from_native(std::string const& s); #else diff --git a/src/escape_string.cpp b/src/escape_string.cpp index bce563f47..a7803c452 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -580,6 +580,32 @@ namespace libtorrent return iconv_convert_impl(s, iconv_handle); } +#elif defined TORRENT_WINDOWS + + std::string convert_to_native(std::string const& s) + { + std::wstring ws; + libtorrent::utf8_wchar(s, ws); + std::string ret; + ret.resize(ws.size() * 4); + std::size_t size = WideCharToMultiByte(CP_ACP, 0, ws.c_str(), -1, &ret[0], ret.size(), NULL, NULL); + if (size == std::size_t(-1)) return s; + ret.resize(size); + return ret; + } + + std::string convert_from_native(std::string const& s) + { + std::wstring ws; + ws.resize(s.size()); + std::size_t size = MultiByteToWideChar(CP_ACP, 0, s.c_str(), -1, &ws[0], ws.size()); + if (size == std::size_t(-1)) return s; + ws.resize(size); + std::string ret; + libtorrent::wchar_utf8(ws, ret); + return ret; + } + #elif TORRENT_USE_LOCALE std::string convert_to_native(std::string const& s)