From 477f22c304dd4e2eae99f708ebad7e57c2cb3c17 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Wed, 30 Aug 2023 23:24:28 +0800 Subject: [PATCH] fix: code smells [autofix.ci] apply automated fixes --- src/article_maker.cc | 21 ++++++++++----------- src/dict/epwing.cc | 10 +++++----- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/article_maker.cc b/src/article_maker.cc index ac1fc90d..c5a78980 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -437,7 +437,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeEmptyPage() const sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & url ) const { string result = makeHtmlHeader( tr( "(picture)" ), QString(), true ) - + "2) history.go(-1)\">" + "" + + R"lit()lit" + R"()" + ""; sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true ); @@ -490,9 +490,8 @@ ArticleRequest::ArticleRequest( QString const & word, emit GlobalBroadcaster::instance()->dictionaryClear( ActiveDictIds{ group.id, word } ); // Accumulate main forms - for ( unsigned x = 0; x < activeDicts.size(); ++x ) { - sptr< Dictionary::WordSearchRequest > s = - activeDicts[ x ]->findHeadwordsForSynonym( gd::removeTrailingZero( word ) ); + for ( const auto & activeDict : activeDicts ) { + auto const s = activeDict->findHeadwordsForSynonym( gd::removeTrailingZero( word ) ); connect( s.get(), &Dictionary::Request::finished, this, &ArticleRequest::altSearchFinished, Qt::QueuedConnection ); @@ -508,7 +507,7 @@ void ArticleRequest::altSearchFinished() return; // Check every request for finishing - for ( list< sptr< Dictionary::WordSearchRequest > >::iterator i = altSearches.begin(); i != altSearches.end(); ) { + for ( auto i = altSearches.begin(); i != altSearches.end(); ) { if ( ( *i )->isFinished() ) { // This one's finished for ( size_t count = ( *i )->matchesCount(), x = 0; x < count; ++x ) @@ -532,8 +531,8 @@ void ArticleRequest::altSearchFinished() vector< wstring > altsVector( alts.begin(), alts.end() ); #ifdef QT_DEBUG - for ( unsigned x = 0; x < altsVector.size(); ++x ) { - qDebug() << "Alt:" << QString::fromStdU32String( altsVector[ x ] ); + for ( const auto & x : altsVector ) { + qDebug() << "Alt:" << QString::fromStdU32String( x ); } #endif @@ -542,12 +541,12 @@ void ArticleRequest::altSearchFinished() if ( activeDicts.size() <= 1 ) articleSizeLimit = -1; // Don't collapse article if only one dictionary presented - for ( unsigned x = 0; x < activeDicts.size(); ++x ) { + for ( const auto & activeDict : activeDicts ) { try { - sptr< Dictionary::DataRequest > r = activeDicts[ x ]->getArticle( + sptr< Dictionary::DataRequest > r = activeDict->getArticle( wordStd, altsVector, - gd::removeTrailingZero( contexts.value( QString::fromStdString( activeDicts[ x ]->getId() ) ) ), + gd::removeTrailingZero( contexts.value( QString::fromStdString( activeDict->getId() ) ) ), ignoreDiacritics ); connect( r.get(), &Dictionary::Request::finished, this, &ArticleRequest::bodyFinished, Qt::QueuedConnection ); @@ -555,7 +554,7 @@ void ArticleRequest::altSearchFinished() bodyRequests.push_back( r ); } catch ( std::exception & e ) { - gdWarning( "getArticle request error (%s) in \"%s\"\n", e.what(), activeDicts[ x ]->getName().c_str() ); + gdWarning( "getArticle request error (%s) in \"%s\"\n", e.what(), activeDict->getName().c_str() ); } } diff --git a/src/dict/epwing.cc b/src/dict/epwing.cc index 86bf619c..7de0f3d4 100644 --- a/src/dict/epwing.cc +++ b/src/dict/epwing.cc @@ -303,15 +303,15 @@ void EpwingDictionary::loadArticle( articleHeadword = string( headword.toUtf8().data() ); articleText = string( text.toUtf8().data() ); - string prefix( "
" ); + const string prefix( "
" ); articleText = prefix + articleText + "
"; } string Epwing::EpwingDictionary::epwing_previous_button( const int & articlePage, const int & articleOffset ) { - QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset ); - string previousLink = R"(

" + tr( "Previous Page" ).toStdString() + "

"; @@ -349,8 +349,8 @@ void EpwingDictionary::loadArticleNextPage( string & articleHeadword, string Epwing::EpwingDictionary::epwing_next_button( const int & articlePage, const int & articleOffset ) { QString refLink = QString( "r%1At%2" ).arg( articlePage ).arg( articleOffset ); - string nextLink = R"(

" - + tr( "Next Page" ).toStdString() + "

"; + string nextLink = R"(

" + tr( "Next Page" ).toStdString() + "

"; return nextLink; }