use iconv on mingw

This commit is contained in:
Arvid Norberg 2011-02-07 17:25:24 +00:00
parent 42902c405c
commit 73e3bbae7b
2 changed files with 27 additions and 28 deletions

View File

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

View File

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