use iconv on mingw
This commit is contained in:
parent
42902c405c
commit
73e3bbae7b
|
@ -143,7 +143,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#elif defined __MINGW32__
|
#elif defined __MINGW32__
|
||||||
#define TORRENT_MINGW
|
#define TORRENT_MINGW
|
||||||
#define TORRENT_WINDOWS
|
#define TORRENT_WINDOWS
|
||||||
#define TORRENT_USE_ICONV 0
|
#define TORRENT_USE_ICONV 1
|
||||||
#define TORRENT_USE_RLIMIT 0
|
#define TORRENT_USE_RLIMIT 0
|
||||||
|
|
||||||
// ==== WINDOWS ===
|
// ==== WINDOWS ===
|
||||||
|
|
|
@ -611,33 +611,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TORRENT_WINDOWS
|
#if TORRENT_USE_ICONV
|
||||||
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
|
|
||||||
std::string iconv_convert_impl(std::string const& s, iconv_t h)
|
std::string iconv_convert_impl(std::string const& s, iconv_t h)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
@ -688,6 +662,31 @@ namespace libtorrent
|
||||||
if (iconv_handle == iconv_t(-1)) return s;
|
if (iconv_handle == iconv_t(-1)) return s;
|
||||||
return iconv_convert_impl(s, iconv_handle);
|
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
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue