From: <man...@us...> - 2015-06-13 14:18:11
|
Revision: 5305 http://sourceforge.net/p/modplug/code/5305 Author: manxorist Date: 2015-06-13 14:18:04 +0000 (Sat, 13 Jun 2015) Log Message: ----------- [Ref] mptString: Add mpt::CharsetLocaleOrUTF8 which does what it says. It is the same as CharsetLocale in tracker builds and in libopenmpt builds compiled without locale support. Otherwise it just assumes UTF8. This simplifies most cases that did check #if defined(MPT_WITH_CHARSET_LOCALE). [Ref] mptString: Kill mpt::ToLocale(str). mpt::ToCharset(mpt::CharsetLocale, str) did and does the same thing and it's used in only few places anyway. Modified Paths: -------------- trunk/OpenMPT/common/Logging.cpp trunk/OpenMPT/common/mptFileIO.h trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/mptStringFormat.cpp trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Settings.cpp trunk/OpenMPT/mptrack/Settings.h trunk/OpenMPT/mptrack/TuningDialog.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/view_com.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/Logging.cpp =================================================================== --- trunk/OpenMPT/common/Logging.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/common/Logging.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -101,11 +101,7 @@ std::clog << "openmpt: " << context.file << "(" << context.line << ")" << ": " -#if defined(MPT_WITH_CHARSET_LOCALE) - << mpt::ToLocale(message) -#else - << mpt::ToCharset(mpt::CharsetUTF8, message) -#endif + << mpt::ToCharset(mpt::CharsetLocaleOrUTF8, message) << " [" << context.function << "]" << std::endl; #endif // MODPLUG_TRACKER @@ -121,11 +117,7 @@ vsnprintf(message, LOGBUF_SIZE, format, va); message[LOGBUF_SIZE - 1] = '\0'; va_end(va); -#if defined(MPT_WITH_CHARSET_LOCALE) - DoLog(context, mpt::ToUnicode(mpt::CharsetLocale, message)); -#else - DoLog(context, mpt::ToUnicode(mpt::CharsetUTF8, message)); -#endif + DoLog(context, mpt::ToUnicode(mpt::CharsetLocaleOrUTF8, message)); } Modified: trunk/OpenMPT/common/mptFileIO.h =================================================================== --- trunk/OpenMPT/common/mptFileIO.h 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/common/mptFileIO.h 2015-06-13 14:18:04 UTC (rev 5305) @@ -94,8 +94,8 @@ template<typename Tbase> inline void fstream_open(Tbase & base, const mpt::PathString & filename, std::ios_base::openmode mode) { -#if defined( MPT_FSTREAM_DO_CONVERSIONS_ANSI) - base.open(mpt::ToLocale(filename.AsNative()).c_str(), mode); +#if defined(MPT_FSTREAM_DO_CONVERSIONS_ANSI) + base.open(mpt::ToCharset(mpt::CharsetLocale, filename.AsNative()).c_str(), mode); #else base.open(filename.AsNative().c_str(), mode); #endif Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/common/mptPathString.h 2015-06-13 14:18:04 UTC (rev 5305) @@ -157,7 +157,7 @@ #endif // conversions #if defined(MPT_WITH_CHARSET_LOCALE) - MPT_DEPRECATED_PATH std::string ToLocale() const { return mpt::ToLocale(path); } + MPT_DEPRECATED_PATH std::string ToLocale() const { return mpt::ToCharset(mpt::CharsetLocale, path); } #endif std::string ToUTF8() const { return mpt::ToCharset(mpt::CharsetUTF8, path); } std::wstring ToWide() const { return path; } @@ -230,7 +230,7 @@ }; #if defined(MPT_WITH_CHARSET_LOCALE) -MPT_DEPRECATED_PATH static inline std::string ToString(const mpt::PathString & x) { return mpt::ToLocale(x.ToUnicode()); } +MPT_DEPRECATED_PATH static inline std::string ToString(const mpt::PathString & x) { return mpt::ToCharset(mpt::CharsetLocale, x.ToUnicode()); } #endif #if MPT_WSTRING_FORMAT static inline std::wstring ToWString(const mpt::PathString & x) { return x.ToWide(); } Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/common/mptString.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -1403,7 +1403,7 @@ #ifdef UNICODE return str.c_str(); #else - return ToLocale(str).c_str(); + return ToCharset(CharsetLocale, str).c_str(); #endif } CString ToCString(Charset from, const std::string &str) @@ -1411,7 +1411,7 @@ #ifdef UNICODE return ToWide(from, str).c_str(); #else - return ToLocale(from, str).c_str(); + return ToCharset(CharsetLocale, from, str).c_str(); #endif } std::wstring ToWide(const CString &str) @@ -1460,7 +1460,7 @@ } CString ToCString(const CStringW &str) { - return ToLocale(str).c_str(); + return ToCharset(CharsetLocale, str).c_str(); } #endif // UNICODE Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/common/mptString.h 2015-06-13 14:18:04 UTC (rev 5305) @@ -153,9 +153,19 @@ CharsetCP437AMS2, CharsetWindows1252, + }; +// Locale in tracker builds, UTF8 in non-locale-aware libopenmpt builds. +#if defined(MPT_WITH_CHARSET_LOCALE) +const Charset CharsetLocaleOrUTF8 = CharsetLocale; +#else +const Charset CharsetLocaleOrUTF8 = CharsetUTF8; +#endif + + + // Checks if the std::string represents an UTF8 string. // This is currently implemented as converting to std::wstring and back assuming UTF8 both ways, // and comparing the result to the original string. @@ -268,20 +278,6 @@ #endif // MFC -#if defined(MPT_WITH_CHARSET_LOCALE) -// Convert to locale-encoded string. -// On Windows, CP_ACP is used, -// otherwise, the global C locale is used. -// If str does not contain any invalid characters, -// this conversion will be lossless iff, and only iff, the system is NOT -// windows AND a UTF8 locale is set. -// Invalid source bytes or characters that are not representable in the -// destination charset will be replaced by some replacement character or string. -template <typename Tsrc> inline std::string ToLocale(const Tsrc &str) { return ToCharset(CharsetLocale, str); } -static inline std::string ToLocale(Charset from, const std::string &str) { return ToCharset(CharsetLocale, from, str); } -#endif - - // mpt::ustring // // mpt::ustring is a string type that can hold unicode strings. Modified: trunk/OpenMPT/common/mptStringFormat.cpp =================================================================== --- trunk/OpenMPT/common/mptStringFormat.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/common/mptStringFormat.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -51,30 +51,16 @@ #endif #if MPT_WSTRING_CONVERT -#if defined(MPT_WITH_CHARSET_LOCALE) -std::string ToString(const std::wstring & x) { return mpt::ToLocale(x); } -std::string ToString(const wchar_t * const & x) { return mpt::ToLocale(x); } -std::string ToString(const wchar_t & x) { return mpt::ToLocale(std::wstring(1, x)); } -#else -std::string ToString(const std::wstring & x) { return mpt::ToCharset(mpt::CharsetUTF8, x); } -std::string ToString(const wchar_t * const & x) { return mpt::ToCharset(mpt::CharsetUTF8, x); } -std::string ToString(const wchar_t & x) { return mpt::ToCharset(mpt::CharsetUTF8, std::wstring(1, x)); } +std::string ToString(const std::wstring & x) { return mpt::ToCharset(mpt::CharsetLocaleOrUTF8, x); } +std::string ToString(const wchar_t * const & x) { return mpt::ToCharset(mpt::CharsetLocaleOrUTF8, x); } +std::string ToString(const wchar_t & x) { return mpt::ToCharset(mpt::CharsetLocaleOrUTF8, std::wstring(1, x)); } #endif -#endif #if MPT_USTRING_MODE_UTF8 -#if defined(MPT_WITH_CHARSET_LOCALE) -std::string ToString(const mpt::ustring & x) { return mpt::ToLocale(x); } -#else -std::string ToString(const mpt::ustring & x) { return mpt::ToCharset(mpt::CharsetUTF8, x); } +std::string ToString(const mpt::ustring & x) { return mpt::ToCharset(mpt::CharsetLocaleOrUTF8, x); } #endif -#endif #if defined(_MFC_VER) -#if defined(MPT_WITH_CHARSET_LOCALE) -std::string ToString(const CString & x) { return mpt::ToLocale(x); } -#else -std::string ToString(const CString & x) { return mpt::ToCharset(mpt::CharsetUTF8, x); } +std::string ToString(const CString & x) { return mpt::ToCharset(mpt::CharsetLocaleOrUTF8, x); } #endif -#endif std::string ToString(const bool & x) { return ToStringHelper(x); } std::string ToString(const signed char & x) { return ToStringHelper(x); } std::string ToString(const unsigned char & x) { return ToStringHelper(x); } @@ -91,15 +77,9 @@ std::string ToString(const long double & x) { return ToStringHelper(x); } #if MPT_WSTRING_FORMAT -#if defined(MPT_WITH_CHARSET_LOCALE) -std::wstring ToWString(const std::string & x) { return mpt::ToWide(mpt::CharsetLocale, x); } -std::wstring ToWString(const char * const & x) { return mpt::ToWide(mpt::CharsetLocale, x); } -std::wstring ToWString(const char & x) { return mpt::ToWide(mpt::CharsetLocale, std::string(1, x)); } -#else -std::wstring ToWString(const std::string & x) { return mpt::ToWide(mpt::CharsetUTF8, x); } -std::wstring ToWString(const char * const & x) { return mpt::ToWide(mpt::CharsetUTF8, x); } -std::wstring ToWString(const char & x) { return mpt::ToWide(mpt::CharsetUTF8, std::string(1, x)); } -#endif +std::wstring ToWString(const std::string & x) { return mpt::ToWide(mpt::CharsetLocaleOrUTF8, x); } +std::wstring ToWString(const char * const & x) { return mpt::ToWide(mpt::CharsetLocaleOrUTF8, x); } +std::wstring ToWString(const char & x) { return mpt::ToWide(mpt::CharsetLocaleOrUTF8, std::string(1, x)); } #if MPT_USTRING_MODE_UTF8 std::wstring ToWString(const mpt::ustring & x) { return mpt::ToWide(x); } #endif Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -452,7 +452,7 @@ if(strcmp(m_VstPlugin.m_pMixStruct->GetName(), "")) Title.Append(m_VstPlugin.m_pMixStruct->GetName()); else - Title.Append(mpt::ToLocale(mpt::CharsetUTF8, m_VstPlugin.m_pMixStruct->GetLibraryName()).c_str()); + Title.Append(mpt::ToCharset(mpt::CharsetLocale, mpt::CharsetUTF8, m_VstPlugin.m_pMixStruct->GetLibraryName()).c_str()); if(m_VstPlugin.isBridged) Title.Append(" (Bridged)"); @@ -952,7 +952,7 @@ m_nInstrument = nIns; _snprintf(pIns->name, CountOf(pIns->name) - 1, _T("%d: %s"), m_VstPlugin.GetSlot() + 1, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetName()); - mpt::String::Copy(pIns->filename, mpt::ToLocale(mpt::CharsetUTF8, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetLibraryName())); + mpt::String::Copy(pIns->filename, mpt::ToCharset(mpt::CharsetLocale, mpt::CharsetUTF8, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetLibraryName())); pIns->nMixPlug = (PLUGINDEX)m_VstPlugin.GetSlot() + 1; pIns->nMidiChannel = 1; // People will forget to change this anyway, so the following lines can lead to some bad surprises after re-opening the module. Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -1281,7 +1281,7 @@ if ((n < 0) || (n >= 4)) n = 0; CString s; GetDlgItemText(IDC_EDIT1, s); - mpt::String::Copy(m_EQ.szName, mpt::ToLocale(s)); + mpt::String::Copy(m_EQ.szName, mpt::ToCharset(mpt::CharsetLocale, s)); mpt::String::SetNullTerminator(m_EQ.szName); TrackerSettings::Instance().m_EqUserPresets[n] = m_EQ; } Modified: trunk/OpenMPT/mptrack/Settings.cpp =================================================================== --- trunk/OpenMPT/mptrack/Settings.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/Settings.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -341,7 +341,7 @@ { ::WritePrivateProfileStringW(GetSection(path).c_str(), GetKey(path).c_str(), val.c_str(), filename.AsNative().c_str()); - if(mpt::ToWide(mpt::CharsetLocale, mpt::ToLocale(val)) != val) // explicit round-trip + if(mpt::ToWide(mpt::CharsetLocale, mpt::ToCharset(mpt::CharsetLocale, val)) != val) // explicit round-trip { // Value is not representable in ANSI CP. // Now check if the string got stored correctly. Modified: trunk/OpenMPT/mptrack/Settings.h =================================================================== --- trunk/OpenMPT/mptrack/Settings.h 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/Settings.h 2015-06-13 14:18:04 UTC (rev 5305) @@ -255,7 +255,7 @@ operator std::string () const { ASSERT(type == SettingTypeString); - return mpt::ToLocale(valueString); + return mpt::ToCharset(mpt::CharsetLocale, valueString); } operator std::wstring () const { Modified: trunk/OpenMPT/mptrack/TuningDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/TuningDialog.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/TuningDialog.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -1556,7 +1556,7 @@ return enSclImportAddTuningFailure; } - pT->SetName(mpt::ToLocale(name)); + pT->SetName(mpt::ToCharset(mpt::CharsetLocale, name)); return enSclImportOk; } Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -515,7 +515,7 @@ const SNDMIXPLUGIN &plugin = sndFile.m_MixPlugins[iOut]; if(plugin.IsValidPlugin()) { - std::string libName = mpt::ToLocale(mpt::CharsetUTF8, plugin.GetLibraryName()); + std::string libName = mpt::ToCharset(mpt::CharsetLocale, mpt::CharsetUTF8, plugin.GetLibraryName()); if(!strcmp(plugin.GetName(), "") || libName != plugin.GetName()) { wsprintf(s, "FX%d: %s", iOut + 1, libName.c_str()); Modified: trunk/OpenMPT/mptrack/view_com.cpp =================================================================== --- trunk/OpenMPT/mptrack/view_com.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/mptrack/view_com.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -388,7 +388,7 @@ case INSLIST_PLUGIN: if (pIns != nullptr && pIns->nMixPlug > 0 && sndFile.m_MixPlugins[pIns->nMixPlug - 1].pMixPlugin != nullptr) { - wsprintf(s, "FX%02u: %s", pIns->nMixPlug, mpt::ToLocale(mpt::CharsetUTF8, sndFile.m_MixPlugins[pIns->nMixPlug - 1].GetLibraryName()).c_str()); + wsprintf(s, "FX%02u: %s", pIns->nMixPlug, mpt::ToCharset(mpt::CharsetLocale, mpt::CharsetUTF8, sndFile.m_MixPlugins[pIns->nMixPlug - 1].GetLibraryName()).c_str()); } break; } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -322,7 +322,7 @@ // Read archive comment if there is no song comment if(songMessage.empty()) { - songMessage.assign(mpt::ToLocale(unarchiver.GetComment())); + songMessage.assign(mpt::ToCharset(mpt::CharsetLocale, unarchiver.GetComment())); } #endif Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/soundlib/Sndfile.h 2015-06-13 14:18:04 UTC (rev 5305) @@ -566,11 +566,7 @@ // logging and user interaction void SetCustomLog(ILog *pLog) { m_pCustomLog = pLog; } void AddToLog(LogLevel level, const mpt::ustring &text) const; -#if defined(MPT_WITH_CHARSET_LOCALE) - /*MPT_DEPRECATED*/ void AddToLog(const std::string &text) const { AddToLog(LogInformation, mpt::ToUnicode(mpt::CharsetLocale, text)); } -#else - /*MPT_DEPRECATED*/ void AddToLog(const std::string &text) const { AddToLog(LogInformation, mpt::ToUnicode(mpt::CharsetUTF8, text)); } -#endif + /*MPT_DEPRECATED*/ void AddToLog(const std::string &text) const { AddToLog(LogInformation, mpt::ToUnicode(mpt::CharsetLocaleOrUTF8, text)); } public: Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2015-06-13 13:54:16 UTC (rev 5304) +++ trunk/OpenMPT/test/test.cpp 2015-06-13 14:18:04 UTC (rev 5305) @@ -700,7 +700,7 @@ VERIFY_EQUAL(mpt::ToUnicode(mpt::CharsetISO8859_1, "a"), MPT_USTRING("a")); VERIFY_EQUAL(mpt::ToUnicode(mpt::CharsetASCII, "a"), MPT_USTRING("a")); #if defined(MPT_WITH_CHARSET_LOCALE) - VERIFY_EQUAL(mpt::ToLocale(MPT_USTRING("a")), "a"); + VERIFY_EQUAL(mpt::ToCharset(mpt::CharsetLocale, MPT_USTRING("a")), "a"); VERIFY_EQUAL(mpt::ToUnicode(mpt::CharsetLocale, "a"), MPT_USTRING("a")); #endif VERIFY_EQUAL(mpt::ToCharset(mpt::CharsetUTF8, MPT_UTF8("a")), "a"); @@ -710,7 +710,7 @@ VERIFY_EQUAL(mpt::ToUnicode(mpt::CharsetISO8859_1, "a"), MPT_UTF8("a")); VERIFY_EQUAL(mpt::ToUnicode(mpt::CharsetASCII, "a"), MPT_UTF8("a")); #if defined(MPT_WITH_CHARSET_LOCALE) - VERIFY_EQUAL(mpt::ToLocale(MPT_UTF8("a")), "a"); + VERIFY_EQUAL(mpt::ToCharset(mpt::CharsetLocale, MPT_UTF8("a")), "a"); VERIFY_EQUAL(mpt::ToUnicode(mpt::CharsetLocale, "a"), MPT_UTF8("a")); #endif @@ -799,7 +799,7 @@ VERIFY_EQUAL(mpt::ToWide(mpt::CharsetISO8859_1, "a"), L"a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetASCII, "a"), L"a"); #if defined(MPT_WITH_CHARSET_LOCALE) - VERIFY_EQUAL(mpt::ToLocale(L"a"), "a"); + VERIFY_EQUAL(mpt::ToCharset(mpt::CharsetLocale, L"a"), "a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetLocale, "a"), L"a"); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |