From bcf25d18a69ce27860c2af9dbba1b8fff83cbaa8 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Fri, 3 Jan 2025 13:55:37 +0800 Subject: [PATCH] opt: remove qtextcodec and refactor code --- src/common/iconv.cc | 3 +-- src/dict/utils/indexedzip.cc | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/common/iconv.cc b/src/common/iconv.cc index f12fdab79..365f75bdb 100644 --- a/src/common/iconv.cc +++ b/src/common/iconv.cc @@ -130,6 +130,5 @@ QString Iconv::findValidEncoding( const QStringList & encodings ) return encoding; } } - // Return utf-8 as fallback. - return QString( "UTF-8" ); + return {}; } diff --git a/src/dict/utils/indexedzip.cc b/src/dict/utils/indexedzip.cc index d2bb8c2c9..85872e18e 100644 --- a/src/dict/utils/indexedzip.cc +++ b/src/dict/utils/indexedzip.cc @@ -180,7 +180,11 @@ bool IndexedZip::indexFile( BtreeIndexing::IndexedWords & zipFileNames, quint32 else { try { //detect encoding. - auto encoding = Iconv::findValidEncoding( { "LOCAL", "IBM437", "CP866", "CP1251" } ); + auto encoding = Iconv::findValidEncoding( { "LOCAL", "IBM437", "CP866", "CP1251", "UTF-8" } ); + if ( encoding.isEmpty() ) { + qWarning() << "Zip warning: failed to detect encoding -- skipping file" << entry.fileName.data(); + continue; + } std::u32string nameInSystemLocale = Iconv::toWstring( encoding.toUtf8().constData(), entry.fileName.constData(), entry.fileName.size() ); if ( !nameInSystemLocale.empty() ) {