From: <man...@us...> - 2013-12-04 14:49:04
|
Revision: 3365 http://sourceforge.net/p/modplug/code/3365 Author: manxorist Date: 2013-12-04 14:48:57 +0000 (Wed, 04 Dec 2013) Log Message: ----------- [Fix] Iconv on MacOS X does not handle wchar_t if no locale is set. Work-around it by using UTF[32|16]-[LE|BE] directly. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/openmpt123/Makefile.config.macosx Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-12-03 21:39:21 UTC (rev 3364) +++ trunk/OpenMPT/common/mptString.cpp 2013-12-04 14:48:57 UTC (rev 3365) @@ -102,6 +102,37 @@ } return 0; } +static const char * Charset_wchar_t() +{ + #if !defined(MPT_ICONV_NO_WCHAR) + return "wchar_t"; + #else // MPT_ICONV_NO_WCHAR + // iconv on OSX does not handle wchar_t if no locale is set + STATIC_ASSERT(sizeof(wchar_t) == 2 || sizeof(wchar_t) == 4); + if(sizeof(wchar_t) == 2) + { + // "UTF-16" generates BOM + #if defined(MPT_PLATFORM_LITTLE_ENDIAN) + return "UTF-16LE"; + #elif defined(MPT_PLATFORM_BIG_ENDIAN) + return "UTF-16BE"; + #else + STATIC_ASSERT(false); + #endif + } else if(sizeof(wchar_t) == 4) + { + // "UTF-32" generates BOM + #if defined(MPT_PLATFORM_LITTLE_ENDIAN) + return "UTF-32LE"; + #elif defined(MPT_PLATFORM_BIG_ENDIAN) + return "UTF-32BE"; + #else + STATIC_ASSERT(false); + #endif + } + return ""; + #endif // !MPT_ICONV_NO_WCHAR | MPT_ICONV_NO_WCHAR +} #endif // WIN32 @@ -122,10 +153,10 @@ return reinterpret_cast<const typename Tdststring::value_type*>(&encoded_string[0]); #else // !WIN32 iconv_t conv = iconv_t(); - conv = iconv_open(CharsetToStringTranslit(charset), "wchar_t"); + conv = iconv_open(CharsetToStringTranslit(charset), Charset_wchar_t()); if(!conv) { - conv = iconv_open(CharsetToString(charset), "wchar_t"); + conv = iconv_open(CharsetToString(charset), Charset_wchar_t()); if(!conv) { throw std::runtime_error("iconv conversion not working"); @@ -178,7 +209,7 @@ return &decoded_string[0]; #else // !WIN32 iconv_t conv = iconv_t(); - conv = iconv_open("wchar_t", CharsetToString(charset)); + conv = iconv_open(Charset_wchar_t(), CharsetToString(charset)); if(!conv) { throw std::runtime_error("iconv conversion not working"); Modified: trunk/OpenMPT/openmpt123/Makefile.config.macosx =================================================================== --- trunk/OpenMPT/openmpt123/Makefile.config.macosx 2013-12-03 21:39:21 UTC (rev 3364) +++ trunk/OpenMPT/openmpt123/Makefile.config.macosx 2013-12-04 14:48:57 UTC (rev 3365) @@ -2,5 +2,6 @@ include Makefile.config.defaults LDLIBS += -liconv +CPPFLAGS += -DMPT_ICONV_NO_WCHAR DYNLINK=0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |