If no BOM was found, check whether decoding the input using the "local 8-Bit" Codepage produces any "replacement" characters (U+FFFD). In that case we assume a decoding error and fall back to Latin-1.

This commit is contained in:
LoRd_MuldeR 2011-12-08 14:46:11 +01:00
parent fba31b51a9
commit 6e819e45b3
2 changed files with 16 additions and 3 deletions

View File

@ -38,5 +38,5 @@ LangString LAMEXP_LANG_LINK_CHANGELOG ${LANG_UKRAINIAN} "Історія В
LangString LAMEXP_LANG_LINK_TRANSLATE ${LANG_UKRAINIAN} "Допомога Перекладачу"
LangString LAMEXP_LANG_LINK_UNINSTALL ${LANG_UKRAINIAN} "Видалення"
LangString LAMEXP_LANG_LINK_FAQ ${LANG_UKRAINIAN} "Часті Питання"
LangString LAMEXP_LANG_LINK_MANUAL ${LANG_UKRAINIAN} "User Manual"
LangString LAMEXP_LANG_LINK_MANUAL ${LANG_UKRAINIAN} "Посібник користувача"
LangString LAMEXP_LANG_PRERELEASE_WARNING ${LANG_UKRAINIAN} "Ви збираєтесь встановити Демо (тестову) версію LameXP!"

View File

@ -558,11 +558,24 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic
}
//Check for UTF-8 BOM in order to guess encoding
bool bUTF8 = false, bForceLatin1 = false;
QByteArray bomCheck = cueFile.peek(128);
bool bUTF8 = bomCheck.contains("\xef\xbb\xbf");
bUTF8 = (!bomCheck.isEmpty()) && bomCheck.contains("\xef\xbb\xbf");
qDebug("Encoding is %s.", (bUTF8 ? "UTF-8" : "Local 8-Bit"));
bomCheck.clear();
//Test selected Codepage for decoding errors
if(!bUTF8)
{
const QString replacementSymbol = QString(QChar(QChar::ReplacementCharacter));
QByteArray data = cueFile.peek(1048576);
if((!data.isEmpty()) && QString::fromLocal8Bit(data.constData(), data.size()).contains(replacementSymbol))
{
qWarning("Decoding error using local 8-Bit codepage. Enforcing Latin-1.");
bForceLatin1 = true;
}
}
QRegExp rxFile("^FILE\\s+(\"[^\"]+\"|\\S+)\\s+(\\w+)$", Qt::CaseInsensitive);
QRegExp rxTrack("^TRACK\\s+(\\d+)\\s(\\w+)$", Qt::CaseInsensitive);
QRegExp rxIndex("^INDEX\\s+(\\d+)\\s+([0-9:]+)$", Qt::CaseInsensitive);
@ -598,7 +611,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic
break;
}
QString line = bUTF8 ? QString::fromUtf8(lineData.constData(), lineData.size()).trimmed() : QString::fromLocal8Bit(lineData.constData(), lineData.size()).trimmed();
QString line = bUTF8 ? QString::fromUtf8(lineData.constData(), lineData.size()).trimmed() : (bForceLatin1 ? QString::fromLatin1(lineData.constData(), lineData.size()).trimmed() : QString::fromLocal8Bit(lineData.constData(), lineData.size()).trimmed());
/* --- FILE --- */
if(rxFile.indexIn(line) >= 0)