From 73e3bbae7b4c70fafd5b387a279df6f571fdc47f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 7 Feb 2011 17:25:24 +0000 Subject: [PATCH] use iconv on mingw --- include/libtorrent/config.hpp | 2 +- src/escape_string.cpp | 53 +++++++++++++++++------------------ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 6db6be482..725566bc7 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -143,7 +143,7 @@ POSSIBILITY OF SUCH DAMAGE. #elif defined __MINGW32__ #define TORRENT_MINGW #define TORRENT_WINDOWS -#define TORRENT_USE_ICONV 0 +#define TORRENT_USE_ICONV 1 #define TORRENT_USE_RLIMIT 0 // ==== WINDOWS === diff --git a/src/escape_string.cpp b/src/escape_string.cpp index 2ce238723..b2c1376ce 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -611,33 +611,7 @@ namespace libtorrent } #endif -#ifdef TORRENT_WINDOWS - std::string convert_to_native(std::string const& s) - { - std::wstring ws; - libtorrent::utf8_wchar(s, ws); - std::size_t size = wcstombs(0, ws.c_str(), 0); - if (size == std::size_t(-1)) return s; - std::string ret; - ret.resize(size); - size = wcstombs(&ret[0], ws.c_str(), size + 1); - 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 = mbstowcs(&ws[0], s.c_str(), s.size()); - if (size == std::size_t(-1)) return s; - std::string ret; - libtorrent::wchar_utf8(ws, ret); - return ret; - } - -#elif TORRENT_USE_ICONV +#if TORRENT_USE_ICONV std::string iconv_convert_impl(std::string const& s, iconv_t h) { std::string ret; @@ -688,6 +662,31 @@ namespace libtorrent if (iconv_handle == iconv_t(-1)) return s; 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::size_t size = wcstombs(0, ws.c_str(), 0); + if (size == std::size_t(-1)) return s; + std::string ret; + ret.resize(size); + size = wcstombs(&ret[0], ws.c_str(), size + 1); + 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 = mbstowcs(&ws[0], s.c_str(), s.size()); + if (size == std::size_t(-1)) return s; + std::string ret; + libtorrent::wchar_utf8(ws, ret); + return ret; + } #endif }