fix(index):修改文本文件解析逻辑

一些格式有问题的文件可能会被解析成乱码,因此检测到编码格式有问题则跳过解析。
This commit is contained in:
JunjieBai 2023-09-12 15:41:34 +08:00
parent 4029b5ca0a
commit b71d5cf5a9
1 changed files with 3 additions and 1 deletions

View File

@ -610,8 +610,10 @@ void FileUtils::getTxtContent(const QString &path, QString &textcontent) {
uchardet_data_end(chardet);
const char *codec = uchardet_get_charset(chardet);
if(QTextCodec::codecForName(codec) == 0)
if(QTextCodec::codecForName(codec) == nullptr) {
qWarning() << "Unsupported Text encoding format" << path << QString::fromLocal8Bit(codec);
return;
}
QTextStream stream(encodedString, QIODevice::ReadOnly);
stream.setCodec(codec);