Commit c09747e1 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Assume UTF-8 in TextFileFormat::readFileUTF8 as fallback

If the contents is not detected as UTF-8/16/32 (TextFileFormat::detect)
and decoding with the given defaultCodec fails, still assume UTF-8.

This affects reading in files for code model indexing. Better read in the
file with the wrong encoding than not reading it at all.

Change-Id: Ibc10b7268ecbed4e7fd50336182f6e71c7d93f5b
Reviewed-by: default avatarPawel Faron <pawelfaron87@wp.pl>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent b52fca40
......@@ -289,18 +289,13 @@ TextFileFormat::ReadResult TextFileFormat::readFileUTF8(const QString &fileName,
Utils::TextFileFormat format = Utils::TextFileFormat::detect(data);
if (!format.codec)
format.codec = defaultCodec ? defaultCodec : QTextCodec::codecForLocale();
if (format.codec->name() == "UTF-8") {
QString target;
if (format.codec->name() == "UTF-8" || !format.decode(data, &target)) {
if (format.hasUtf8Bom)
data.remove(0, 3);
*plainText = data;
return Utils::TextFileFormat::ReadSuccess;
}
QString target;
if (!format.decode(data, &target)) {
*errorString = QCoreApplication::translate("Utils::TextFileFormat", "An encoding error was encountered.");
return Utils::TextFileFormat::ReadEncodingError;
}
*plainText = target.toUtf8();
return Utils::TextFileFormat::ReadSuccess;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment