merged fix from RC_0_16

This commit is contained in:
Arvid Norberg 2013-01-21 18:54:45 +00:00
parent 2f995f77a8
commit a301d119fa
3 changed files with 28 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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)