From: <man...@us...> - 2013-12-04 16:34:55
|
Revision: 3370 http://sourceforge.net/p/modplug/code/3370 Author: manxorist Date: 2013-12-04 16:34:48 +0000 (Wed, 04 Dec 2013) Log Message: ----------- [Ref] libopenmpt: Cleanup charset conversion. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Tables.cpp Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-12-04 15:18:02 UTC (rev 3369) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-12-04 16:34:48 UTC (rev 3370) @@ -226,19 +226,7 @@ } std::string module_impl::mod_string_to_utf8( const std::string & encoded ) const { - std::string encoding = m_sndFile->GetCharset().second; - std::transform( encoding.begin(), encoding.end(), encoding.begin(), tolower ); - mpt::Charset charset = mpt::CharsetASCII; - if ( encoding == "" ) { charset = mpt::CharsetASCII; } // fallback - else if ( encoding == "utf-8" ) { charset = mpt::CharsetUTF8; } - else if ( encoding == "ascii" ) { charset = mpt::CharsetASCII; } - else if ( encoding == "us-ascii" ) { charset = mpt::CharsetASCII; } - else if ( encoding == "iso-8859-1" ) { charset = mpt::CharsetISO8859_1; } - else if ( encoding == "iso-8859-15" ) { charset = mpt::CharsetISO8859_15; } - else if ( encoding == "cp437" ) { charset = mpt::CharsetCP437; } - else if ( encoding == "windows-1252" ) { charset = mpt::CharsetWindows1252; } - else { charset = mpt::CharsetASCII; } // fallback - return mpt::To( mpt::CharsetUTF8, charset, encoded ); + return mpt::To( mpt::CharsetUTF8, m_sndFile->GetCharset().second, encoded ); } void module_impl::apply_mixer_settings( std::int32_t samplerate, int channels ) { if ( Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-12-04 15:18:02 UTC (rev 3369) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-12-04 16:34:48 UTC (rev 3370) @@ -477,7 +477,7 @@ MODCONTAINERTYPE GetContainerType() const { return m_ContainerType; } // rough heuristic, could be improved - std::pair<MOD_CHARSET_CERTAINTY, std::string> GetCharset() const { return GetCharsetFromModType(GetType()); } + std::pair<MOD_CHARSET_CERTAINTY, mpt::Charset> GetCharset() const { return GetCharsetFromModType(GetType()); } void SetPreAmp(UINT vol); UINT GetPreAmp() const { return m_MixerSettings.m_nPreAmp; } @@ -576,7 +576,7 @@ bool ReadMID(const LPCBYTE lpStream, DWORD dwMemLength, ModLoadingFlags loadFlags = loadCompleteModule); static std::vector<const char *> GetSupportedExtensions(bool otherFormats); - static std::pair<MOD_CHARSET_CERTAINTY, std::string> GetCharsetFromModType(MODTYPE modtype); + static std::pair<MOD_CHARSET_CERTAINTY, mpt::Charset> GetCharsetFromModType(MODTYPE modtype); static const char * ModTypeToString(MODTYPE modtype); static std::string ModContainerTypeToString(MODCONTAINERTYPE containertype); static std::string ModTypeToTracker(MODTYPE modtype); Modified: trunk/OpenMPT/soundlib/Tables.cpp =================================================================== --- trunk/OpenMPT/soundlib/Tables.cpp 2013-12-04 15:18:02 UTC (rev 3369) +++ trunk/OpenMPT/soundlib/Tables.cpp 2013-12-04 16:34:48 UTC (rev 3370) @@ -139,51 +139,51 @@ { MODTYPE type; MOD_CHARSET_CERTAINTY certainty; - const char *charset; + mpt::Charset charset; }; static const ModCharsetInfo ModCharsetInfos[] = { // Amiga - { MOD_TYPE_OKT , MOD_CHARSET_IS , "ISO-8859-1" }, - { MOD_TYPE_DBM , MOD_CHARSET_IS , "ISO-8859-1" }, - { MOD_TYPE_DIGI, MOD_CHARSET_IS , "ISO-8859-1" }, + { MOD_TYPE_OKT , MOD_CHARSET_IS , mpt::CharsetISO8859_1 }, + { MOD_TYPE_DBM , MOD_CHARSET_IS , mpt::CharsetISO8859_1 }, + { MOD_TYPE_DIGI, MOD_CHARSET_IS , mpt::CharsetISO8859_1 }, // Amiga // DOS - { MOD_TYPE_MOD , MOD_CHARSET_MAYBE , "ISO-8859-1" }, - { MOD_TYPE_MED , MOD_CHARSET_MAYBE , "ISO-8859-1" }, + { MOD_TYPE_MOD , MOD_CHARSET_MAYBE , mpt::CharsetISO8859_1 }, + { MOD_TYPE_MED , MOD_CHARSET_MAYBE , mpt::CharsetISO8859_1 }, // DOS - { MOD_TYPE_S3M , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_XM , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_MTM , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_IT , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_669 , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_STM , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_FAR , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_AMF , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_AMF0, MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_MDL , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_DMF , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_PTM , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_PSM , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_J2B , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_IMF , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_ULT , MOD_CHARSET_IS , "cp437" }, - { MOD_TYPE_AMS , MOD_CHARSET_IS , "Windows-1252"}, // We convert the custom AMS special character set to our own set. - { MOD_TYPE_AMS2, MOD_CHARSET_IS , "Windows-1252"}, // ditto - { MOD_TYPE_DSM , MOD_CHARSET_IS , "cp437" }, + { MOD_TYPE_S3M , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_XM , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_MTM , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_IT , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_669 , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_STM , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_FAR , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_AMF , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_AMF0, MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_MDL , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_DMF , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_PTM , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_PSM , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_J2B , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_IMF , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_ULT , MOD_CHARSET_IS , mpt::CharsetCP437 }, + { MOD_TYPE_AMS , MOD_CHARSET_IS , mpt::CharsetWindows1252}, // We convert the custom AMS special character set to our own set. + { MOD_TYPE_AMS2, MOD_CHARSET_IS , mpt::CharsetWindows1252}, // ditto + { MOD_TYPE_DSM , MOD_CHARSET_IS , mpt::CharsetCP437 }, // Windows - { MOD_TYPE_MT2 , MOD_CHARSET_MAYBE , "Windows-1252"}, - { MOD_TYPE_MPT , MOD_CHARSET_MAYBE , "Windows-1252"}, + { MOD_TYPE_MT2 , MOD_CHARSET_MAYBE , mpt::CharsetWindows1252}, + { MOD_TYPE_MPT , MOD_CHARSET_MAYBE , mpt::CharsetWindows1252}, // random stuff - { MOD_TYPE_MID , MOD_CHARSET_IS , "US-ASCII" }, - { MOD_TYPE_WAV , MOD_CHARSET_MAYBE , "US-ASCII" }, + { MOD_TYPE_MID , MOD_CHARSET_IS , mpt::CharsetASCII }, + { MOD_TYPE_WAV , MOD_CHARSET_MAYBE , mpt::CharsetASCII }, // end - { MOD_TYPE_NONE, MOD_CHARSET_UNKNOWN, "" } + { MOD_TYPE_NONE, MOD_CHARSET_UNKNOWN, mpt::CharsetASCII } }; -std::pair<MOD_CHARSET_CERTAINTY, std::string> CSoundFile::GetCharsetFromModType(MODTYPE modtype) -//---------------------------------------------------------------------------------------------- +std::pair<MOD_CHARSET_CERTAINTY, mpt::Charset> CSoundFile::GetCharsetFromModType(MODTYPE modtype) +//----------------------------------------------------------------------------------------------- { // This is just a rough heuristic. // It could be improved by adjusting the charset according to the tracker that had been used to save the file. @@ -195,7 +195,7 @@ } } // fallback - return std::make_pair(MOD_CHARSET_UNKNOWN, ""); + return std::make_pair(MOD_CHARSET_UNKNOWN, mpt::CharsetASCII); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |