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:
parent
fba31b51a9
commit
6e819e45b3
@ -38,5 +38,5 @@ LangString LAMEXP_LANG_LINK_CHANGELOG ${LANG_UKRAINIAN} "Історія В
|
|||||||
LangString LAMEXP_LANG_LINK_TRANSLATE ${LANG_UKRAINIAN} "Допомога Перекладачу"
|
LangString LAMEXP_LANG_LINK_TRANSLATE ${LANG_UKRAINIAN} "Допомога Перекладачу"
|
||||||
LangString LAMEXP_LANG_LINK_UNINSTALL ${LANG_UKRAINIAN} "Видалення"
|
LangString LAMEXP_LANG_LINK_UNINSTALL ${LANG_UKRAINIAN} "Видалення"
|
||||||
LangString LAMEXP_LANG_LINK_FAQ ${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!"
|
LangString LAMEXP_LANG_PRERELEASE_WARNING ${LANG_UKRAINIAN} "Ви збираєтесь встановити Демо (тестову) версію LameXP!"
|
||||||
|
@ -558,11 +558,24 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check for UTF-8 BOM in order to guess encoding
|
//Check for UTF-8 BOM in order to guess encoding
|
||||||
|
bool bUTF8 = false, bForceLatin1 = false;
|
||||||
QByteArray bomCheck = cueFile.peek(128);
|
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"));
|
qDebug("Encoding is %s.", (bUTF8 ? "UTF-8" : "Local 8-Bit"));
|
||||||
bomCheck.clear();
|
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 rxFile("^FILE\\s+(\"[^\"]+\"|\\S+)\\s+(\\w+)$", Qt::CaseInsensitive);
|
||||||
QRegExp rxTrack("^TRACK\\s+(\\d+)\\s(\\w+)$", Qt::CaseInsensitive);
|
QRegExp rxTrack("^TRACK\\s+(\\d+)\\s(\\w+)$", Qt::CaseInsensitive);
|
||||||
QRegExp rxIndex("^INDEX\\s+(\\d+)\\s+([0-9:]+)$", 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;
|
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 --- */
|
/* --- FILE --- */
|
||||||
if(rxFile.indexIn(line) >= 0)
|
if(rxFile.indexIn(line) >= 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user