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

一些格式有问题的文件可能会被解析成乱码,因此检测到编码格式有问题则跳过解析。
This commit is contained in:
JunjieBai 2023-09-12 15:41:34 +08:00 committed by iaom
parent 04d54f5e2d
commit b328bc8cb8
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); uchardet_data_end(chardet);
const char *codec = uchardet_get_charset(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); qWarning() << "Unsupported Text encoding format" << path << QString::fromLocal8Bit(codec);
return;
}
QTextStream stream(encodedString, QIODevice::ReadOnly); QTextStream stream(encodedString, QIODevice::ReadOnly);
stream.setCodec(codec); stream.setCodec(codec);