From 118a75ebe7d98aa1782c1d79876daa2f0398caf1 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 22 Feb 2011 03:09:13 +0000 Subject: [PATCH] generalized string conversion for libc --- include/libtorrent/config.hpp | 9 ++++++++- include/libtorrent/escape_string.hpp | 2 +- src/escape_string.cpp | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 9500bb291..5d453d8c6 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -142,6 +142,7 @@ POSSIBILITY OF SUCH DAMAGE. #if defined __APPLE__ #ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 0 +#define TORRENT_USE_LOCALE 0 #endif #endif #define TORRENT_HAS_FALLOCATE 0 @@ -157,7 +158,8 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_MINGW #define TORRENT_WINDOWS #ifndef TORRENT_USE_ICONV -#define TORRENT_USE_ICONV 1 +#define TORRENT_USE_ICONV 0 +#define TORRENT_USE_LOCALE 1 #endif #define TORRENT_USE_RLIMIT 0 @@ -169,6 +171,7 @@ POSSIBILITY OF SUCH DAMAGE. // is necessary #ifndef TORRENT_USE_ICONV #define TORRENT_USE_ICONV 0 +#define TORRENT_USE_LOCALE 1 #endif #define TORRENT_USE_RLIMIT 0 #define TORRENT_HAS_FALLOCATE 0 @@ -257,6 +260,10 @@ inline int snprintf(char* buf, int len, char const* fmt, ...) #define TORRENT_USE_ICONV 1 #endif +#ifndef TORRENT_USE_LOCALE +#define TORRENT_USE_LOCALE 0 +#endif + #ifndef TORRENT_BROKEN_UNIONS #define TORRENT_BROKEN_UNIONS 0 #endif diff --git a/include/libtorrent/escape_string.hpp b/include/libtorrent/escape_string.hpp index 0d310fb77..5aa7163a7 100644 --- a/include/libtorrent/escape_string.hpp +++ b/include/libtorrent/escape_string.hpp @@ -90,7 +90,7 @@ namespace libtorrent TORRENT_EXPORT std::string convert_from_wstring(std::wstring const& s); #endif -#if defined TORRENT_WINDOWS || TORRENT_USE_ICONV +#if TORRENT_USE_ICONV || TORRENT_USE_LOCALE TORRENT_EXPORT std::string convert_to_native(std::string const& s); TORRENT_EXPORT std::string convert_from_native(std::string const& s); #else diff --git a/src/escape_string.cpp b/src/escape_string.cpp index d9e7585c7..a09e69497 100644 --- a/src/escape_string.cpp +++ b/src/escape_string.cpp @@ -657,7 +657,9 @@ namespace libtorrent if (iconv_handle == iconv_t(-1)) return s; return iconv_convert_impl(s, iconv_handle); } -#elif defined TORRENT_WINDOWS + +#elif TORRENT_USE_LOCALE + std::string convert_to_native(std::string const& s) { std::wstring ws; @@ -682,6 +684,7 @@ namespace libtorrent libtorrent::wchar_utf8(ws, ret); return ret; } + #endif }