From: <man...@us...> - 2013-12-04 15:07:12
|
Revision: 3368 http://sourceforge.net/p/modplug/code/3368 Author: manxorist Date: 2013-12-04 15:07:04 +0000 (Wed, 04 Dec 2013) Log Message: ----------- [Fix] libopenmpt: Add a compile time option MPT_CHARSET_CPP which uses pure c++ instead of iconv or Win32 for doing character encoding conversions. Iconv on MacOS X does not work if no C locale is set and thus is unusable in a library. Instead, we now implement locale-char conversions via the std::locale codecvt facet (trying "", global(), classic() and raw-Ascii locales in that order). For conversion to UTF-8, the C++11 std::codecvt_utf8 is used. All other conversions are either implemented directly or done via a standard 1:1 codepoint mapping table (i.e. no similarity substitutions are done). As this implementation depends on C++11 features, it is for now only used on MacOS X. Windows continues to use WINAPI for conversion and other unices continue to use iconv. 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-04 14:51:16 UTC (rev 3367) +++ trunk/OpenMPT/common/mptString.cpp 2013-12-04 15:07:04 UTC (rev 3368) @@ -10,7 +10,11 @@ #include "stdafx.h" #include "mptString.h" +#if defined(MPT_CHARSET_CPP) +#include <codecvt> +#endif #include <iomanip> +#include <iterator> #include <locale> #include <sstream> #include <string> @@ -19,7 +23,7 @@ #include <cstdarg> -#if !defined(WIN32) +#if !defined(MPT_CHARSET_CPP) && !defined(WIN32) #include <iconv.h> #endif // !WIN32 @@ -58,7 +62,365 @@ #endif -#if defined(WIN32) + +#if defined(MPT_CHARSET_CPP) + +/* +default 1:1 mapping +static const uint32 CharsetTableISO8859_1[256] = { + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088,0x0089,0x008a,0x008b,0x008c,0x008d,0x008e,0x008f, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009a,0x009b,0x009c,0x009d,0x009e,0x009f, + 0x00a0,0x00a1,0x00a2,0x00a3,0x00a4,0x00a5,0x00a6,0x00a7,0x00a8,0x00a9,0x00aa,0x00ab,0x00ac,0x00ad,0x00ae,0x00af, + 0x00b0,0x00b1,0x00b2,0x00b3,0x00b4,0x00b5,0x00b6,0x00b7,0x00b8,0x00b9,0x00ba,0x00bb,0x00bc,0x00bd,0x00be,0x00bf, + 0x00c0,0x00c1,0x00c2,0x00c3,0x00c4,0x00c5,0x00c6,0x00c7,0x00c8,0x00c9,0x00ca,0x00cb,0x00cc,0x00cd,0x00ce,0x00cf, + 0x00d0,0x00d1,0x00d2,0x00d3,0x00d4,0x00d5,0x00d6,0x00d7,0x00d8,0x00d9,0x00da,0x00db,0x00dc,0x00dd,0x00de,0x00df, + 0x00e0,0x00e1,0x00e2,0x00e3,0x00e4,0x00e5,0x00e6,0x00e7,0x00e8,0x00e9,0x00ea,0x00eb,0x00ec,0x00ed,0x00ee,0x00ef, + 0x00f0,0x00f1,0x00f2,0x00f3,0x00f4,0x00f5,0x00f6,0x00f7,0x00f8,0x00f9,0x00fa,0x00fb,0x00fc,0x00fd,0x00fe,0x00ff +}; +*/ + +static const uint32 CharsetTableISO8859_15[256] = { + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,0x0088,0x0089,0x008a,0x008b,0x008c,0x008d,0x008e,0x008f, + 0x0090,0x0091,0x0092,0x0093,0x0094,0x0095,0x0096,0x0097,0x0098,0x0099,0x009a,0x009b,0x009c,0x009d,0x009e,0x009f, + 0x00a0,0x00a1,0x00a2,0x00a3,0x20ac,0x00a5,0x0160,0x00a7,0x0161,0x00a9,0x00aa,0x00ab,0x00ac,0x00ad,0x00ae,0x00af, + 0x00b0,0x00b1,0x00b2,0x00b3,0x017d,0x00b5,0x00b6,0x00b7,0x017e,0x00b9,0x00ba,0x00bb,0x0152,0x0153,0x0178,0x00bf, + 0x00c0,0x00c1,0x00c2,0x00c3,0x00c4,0x00c5,0x00c6,0x00c7,0x00c8,0x00c9,0x00ca,0x00cb,0x00cc,0x00cd,0x00ce,0x00cf, + 0x00d0,0x00d1,0x00d2,0x00d3,0x00d4,0x00d5,0x00d6,0x00d7,0x00d8,0x00d9,0x00da,0x00db,0x00dc,0x00dd,0x00de,0x00df, + 0x00e0,0x00e1,0x00e2,0x00e3,0x00e4,0x00e5,0x00e6,0x00e7,0x00e8,0x00e9,0x00ea,0x00eb,0x00ec,0x00ed,0x00ee,0x00ef, + 0x00f0,0x00f1,0x00f2,0x00f3,0x00f4,0x00f5,0x00f6,0x00f7,0x00f8,0x00f9,0x00fa,0x00fb,0x00fc,0x00fd,0x00fe,0x00ff +}; + +static const uint32 CharsetTableWindows1252[256] = { + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x007f, + 0x20ac,0x0081,0x201a,0x0192,0x201e,0x2026,0x2020,0x2021,0x02c6,0x2030,0x0160,0x2039,0x0152,0x008d,0x017d,0x008f, + 0x0090,0x2018,0x2019,0x201c,0x201d,0x2022,0x2013,0x2014,0x02dc,0x2122,0x0161,0x203a,0x0153,0x009d,0x017e,0x0178, + 0x00a0,0x00a1,0x00a2,0x00a3,0x00a4,0x00a5,0x00a6,0x00a7,0x00a8,0x00a9,0x00aa,0x00ab,0x00ac,0x00ad,0x00ae,0x00af, + 0x00b0,0x00b1,0x00b2,0x00b3,0x00b4,0x00b5,0x00b6,0x00b7,0x00b8,0x00b9,0x00ba,0x00bb,0x00bc,0x00bd,0x00be,0x00bf, + 0x00c0,0x00c1,0x00c2,0x00c3,0x00c4,0x00c5,0x00c6,0x00c7,0x00c8,0x00c9,0x00ca,0x00cb,0x00cc,0x00cd,0x00ce,0x00cf, + 0x00d0,0x00d1,0x00d2,0x00d3,0x00d4,0x00d5,0x00d6,0x00d7,0x00d8,0x00d9,0x00da,0x00db,0x00dc,0x00dd,0x00de,0x00df, + 0x00e0,0x00e1,0x00e2,0x00e3,0x00e4,0x00e5,0x00e6,0x00e7,0x00e8,0x00e9,0x00ea,0x00eb,0x00ec,0x00ed,0x00ee,0x00ef, + 0x00f0,0x00f1,0x00f2,0x00f3,0x00f4,0x00f5,0x00f6,0x00f7,0x00f8,0x00f9,0x00fa,0x00fb,0x00fc,0x00fd,0x00fe,0x00ff +}; + +static const uint32 CharsetTableCP437[256] = { + 0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x000e,0x000f, + 0x0010,0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x0017,0x0018,0x0019,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, + 0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f, + 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f, + 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f, + 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f, + 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f, + 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x2302, + 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5, + 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20a7,0x0192, + 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb, + 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510, + 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567, + 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580, + 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229, + 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0 +}; + +static std::wstring FromTable(const std::string &str, const uint32 (&table)[256], wchar_t replacement = L'\uFFFD') +//---------------------------------------------------------------------------------------------------------------- +{ + std::wstring res; + for(std::size_t i = 0; i < str.length(); ++i) + { + uint8 c = str[i]; + if(c <= CountOf(table)) + { + res.push_back(static_cast<wchar_t>(static_cast<uint32>(table[c]))); + } else + { + res.push_back(replacement); + } + } + return res; +} + +static std::string ToTable(const std::wstring &str, const uint32 (&table)[256], char replacement = '?') +//----------------------------------------------------------------------------------------------------- +{ + std::string res; + for(std::size_t i = 0; i < str.length(); ++i) + { + uint32 c = str[i]; + bool found = false; + for(std::size_t x = 0; x < CountOf(table); ++x) + { + if(c == table[x]) + { + res.push_back(static_cast<char>(static_cast<uint8>(x))); + found = true; + break; + } + } + if(!found) + { + res.push_back(replacement); + } + } + return res; +} + +static std::wstring FromAscii(const std::string &str, wchar_t replacement = L'\uFFFD') +//------------------------------------------------------------------------------------ +{ + std::wstring res; + for(std::size_t i = 0; i < str.length(); ++i) + { + uint8 c = str[i]; + if(c <= 0x7f) + { + res.push_back(static_cast<wchar_t>(static_cast<uint32>(c))); + } else + { + res.push_back(replacement); + } + } + return res; +} + +static std::string ToAscii(const std::wstring &str, char replacement = '?') +//------------------------------------------------------------------------- +{ + std::string res; + for(std::size_t i = 0; i < str.length(); ++i) + { + uint32 c = str[i]; + if(c <= 0x7f) + { + res.push_back(static_cast<char>(static_cast<uint8>(c))); + } else + { + res.push_back(replacement); + } + } + return res; +} + +static std::wstring FromISO_8859_1(const std::string &str, wchar_t replacement = L'\uFFFD') +//----------------------------------------------------------------------------------------- +{ + MPT_UNREFERENCED_PARAMETER(replacement); + std::wstring res; + for(std::size_t i = 0; i < str.length(); ++i) + { + uint8 c = str[i]; + res.push_back(static_cast<wchar_t>(static_cast<uint32>(c))); + } + return res; +} + +static std::string ToISO_8859_1(const std::wstring &str, char replacement = '?') +//------------------------------------------------------------------------------ +{ + std::string res; + for(std::size_t i = 0; i < str.length(); ++i) + { + uint32 c = str[i]; + if(c <= 0xff) + { + res.push_back(static_cast<char>(static_cast<uint8>(c))); + } else + { + res.push_back(replacement); + } + } + return res; +} + +static std::wstring LocaleDecode(const std::string &str, const std::locale & locale, wchar_t replacement = L'\uFFFD') +//------------------------------------------------------------------------------------------------------------------- +{ + if(str.empty()) + { + return std::wstring(); + } + std::vector<wchar_t> out; + typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type; + std::mbstate_t state = std::mbstate_t(); + const codecvt_type & facet = std::use_facet<codecvt_type>(locale); + codecvt_type::result result = codecvt_type::partial; + const char * in_begin = &*str.begin(); + const char * in_end = in_begin + str.length(); + out.resize((in_end - in_begin) * (facet.max_length() + 1)); + wchar_t * out_begin = out.data(); + wchar_t * out_end = out.data() + out.size(); + const char * in_next = nullptr; + wchar_t * out_next = nullptr; + do + { + in_next = nullptr; + out_next = nullptr; + result = facet.in(state, in_begin, in_end, in_next, out_begin, out_end, out_next); + if(result == codecvt_type::partial || (result == codecvt_type::error && out_next == out_end)) + { + out.resize(out.size() * 2); + in_begin = in_next; + out_begin = out.data() + (out_next - out_begin); + out_end = out.data() + out.size(); + continue; + } + if(result == codecvt_type::error) + { + ++in_next; + *out_next = replacement; + ++out_next; + } + in_begin = in_next; + out_begin = out_next; + } while(result == codecvt_type::error && in_next < in_end && out_next < out_end); + return std::wstring(out.data(), out_next); +} + +static std::string LocaleEncode(const std::wstring &str, const std::locale & locale, char replacement = '?') +//---------------------------------------------------------------------------------------------------------- +{ + if(str.empty()) + { + return std::string(); + } + std::vector<char> out; + typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type; + std::mbstate_t state = std::mbstate_t(); + const codecvt_type & facet = std::use_facet<codecvt_type>(locale); + codecvt_type::result result = codecvt_type::partial; + const wchar_t * in_begin = &*str.begin(); + const wchar_t * in_end = in_begin + str.length(); + out.resize((in_end - in_begin) * (facet.max_length() + 1)); + char * out_begin = out.data(); + char * out_end = out.data() + out.size(); + const wchar_t * in_next = nullptr; + char * out_next = nullptr; + do + { + in_next = nullptr; + out_next = nullptr; + result = facet.out(state, in_begin, in_end, in_next, out_begin, out_end, out_next); + if(result == codecvt_type::partial || (result == codecvt_type::error && out_next == out_end)) + { + out.resize(out.size() * 2); + in_begin = in_next; + out_begin = out.data() + (out_next - out_begin); + out_end = out.data() + out.size(); + continue; + } + if(result == codecvt_type::error) + { + ++in_next; + *out_next = replacement; + ++out_next; + } + in_begin = in_next; + out_begin = out_next; + } while(result == codecvt_type::error && in_next < in_end && out_next < out_end); + return std::string(out.data(), out_next); +} + +static std::wstring FromLocale(const std::string &str, wchar_t replacement = L'\uFFFD') +//------------------------------------------------------------------------------------- +{ + try + { + std::locale locale(""); // user locale + return String::LocaleDecode(str, locale, replacement); + } catch(...) + { + // nothing + } + try + { + std::locale locale; // current c++ locale + return String::LocaleDecode(str, locale, replacement); + } catch(...) + { + // nothing + } + try + { + std::locale locale = std::locale::classic(); // "C" locale + return String::LocaleDecode(str, locale, replacement); + } catch(...) + { + // nothing + } + ASSERT(false); + return String::FromAscii(str, replacement); // fallback +} + +static std::string ToLocale(const std::wstring &str, char replacement = '?') +//-------------------------------------------------------------------------- +{ + try + { + std::locale locale(""); // user locale + return String::LocaleEncode(str, locale, replacement); + } catch(...) + { + // nothing + } + try + { + std::locale locale; // current c++ locale + return String::LocaleEncode(str, locale, replacement); + } catch(...) + { + // nothing + } + try + { + std::locale locale = std::locale::classic(); // "C" locale + return String::LocaleEncode(str, locale, replacement); + } catch(...) + { + // nothing + } + ASSERT(false); + return String::ToAscii(str, replacement); // fallback +} + +static std::wstring FromUTF8(const std::string &str, wchar_t replacement = L'\uFFFD') +//----------------------------------------------------------------------------------- +{ + MPT_UNREFERENCED_PARAMETER(replacement); + std::wstring_convert<std::codecvt_utf8<wchar_t> > conv; + return conv.from_bytes(str); +} + +static std::string ToUTF8(const std::wstring &str, char replacement = '?') +//------------------------------------------------------------------------ +{ + MPT_UNREFERENCED_PARAMETER(replacement); + std::wstring_convert<std::codecvt_utf8<wchar_t> > conv; + return conv.to_bytes(str); +} + +#elif defined(WIN32) static UINT CharsetToCodepage(Charset charset) { switch(charset) @@ -141,7 +503,22 @@ Tdststring EncodeImpl(Charset charset, const std::wstring &src) { STATIC_ASSERT(sizeof(typename Tdststring::value_type) == sizeof(char)); - #if defined(WIN32) + #if defined(MPT_CHARSET_CPP) + std::string out; + switch(charset) + { + case CharsetLocale: out = String::ToLocale(src); break; + case CharsetUTF8: out = String::ToUTF8(src); break; + case CharsetASCII: out = String::ToAscii(src); break; + case CharsetISO8859_1: out = String::ToISO_8859_1(src); break; + case CharsetISO8859_15: out = String::To8bit(src, CharsetTableISO8859_15); break; + case CharsetCP437: out = String::To8bit(src, CharsetTableCP437); break; + case CharsetWindows1252: out = String::To8bit(src, CharsetTableWindows1252); break; + } + Tdststring result; + std::copy(out.begin(), out.end(), std::back_inserter(result)); + return result; + #elif defined(WIN32) const UINT codepage = CharsetToCodepage(charset); int required_size = WideCharToMultiByte(codepage, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr); if(required_size <= 0) @@ -197,7 +574,22 @@ std::wstring DecodeImpl(Charset charset, const Tsrcstring &src) { STATIC_ASSERT(sizeof(typename Tsrcstring::value_type) == sizeof(char)); - #if defined(WIN32) + #if defined(MPT_CHARSET_CPP) + std::string in; + std::copy(src.begin(), src.end(), std::back_inserter(in)); + std::wstring out; + switch(charset) + { + case CharsetLocale: out = String::FromLocale(in); break; + case CharsetUTF8: out = String::FromUTF8(in); break; + case CharsetASCII: out = String::FromAscii(in); break; + case CharsetISO8859_1: out = String::FromISO_8859_1(in); break; + case CharsetISO8859_15: out = String::From8bit(in, CharsetTableISO8859_15); break; + case CharsetCP437: out = String::From8bit(in, CharsetTableCP437); break; + case CharsetWindows1252: out = String::From8bit(in, CharsetTableWindows1252); break; + } + return out; + #elif defined(WIN32) const UINT codepage = CharsetToCodepage(charset); int required_size = MultiByteToWideChar(codepage, 0, reinterpret_cast<const char*>(src.c_str()), -1, nullptr, 0); if(required_size <= 0) @@ -262,7 +654,7 @@ { return Tdststring(reinterpret_cast<const typename Tdststring::value_type*>(&*src.begin()), reinterpret_cast<const typename Tdststring::value_type*>(&*src.end())); } - #if defined(WIN32) + #if defined(MPT_CHARSET_CPP) || defined(WIN32) return EncodeImpl<Tdststring>(to, DecodeImpl(from, src)); #else // !WIN32 iconv_t conv = iconv_t(); Modified: trunk/OpenMPT/openmpt123/Makefile.config.macosx =================================================================== --- trunk/OpenMPT/openmpt123/Makefile.config.macosx 2013-12-04 14:51:16 UTC (rev 3367) +++ trunk/OpenMPT/openmpt123/Makefile.config.macosx 2013-12-04 15:07:04 UTC (rev 3368) @@ -1,7 +1,9 @@ include Makefile.config.defaults -LDLIBS += -liconv -CPPFLAGS += -DMPT_ICONV_NO_WCHAR +#LDLIBS += -liconv +#CPPFLAGS += -DMPT_ICONV_NO_WCHAR +CPPFLAGS += -DMPT_CHARSET_CPP + DYNLINK=0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |