fix: code smells

[autofix.ci] apply automated fixes
This commit is contained in:
YiFang Xiao 2023-08-30 23:24:28 +08:00
parent 791da91645
commit 477f22c304
2 changed files with 15 additions and 16 deletions

View file

@ -437,7 +437,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeEmptyPage() const
sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & url ) const sptr< Dictionary::DataRequest > ArticleMaker::makePicturePage( string const & url ) const
{ {
string result = makeHtmlHeader( tr( "(picture)" ), QString(), true ) string result = makeHtmlHeader( tr( "(picture)" ), QString(), true )
+ "<a href=\"javascript: if(history.length>2) history.go(-1)\">" + "<img src=\"" + url + "\" /></a>" + R"lit(<a href="javascript: if(history.length>2) history.go(-1)">)lit" + R"(<img src=")" + url + R"(" /></a>)"
+ "</body></html>"; + "</body></html>";
sptr< Dictionary::DataRequestInstant > r = std::make_shared< Dictionary::DataRequestInstant >( true ); 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 } ); emit GlobalBroadcaster::instance()->dictionaryClear( ActiveDictIds{ group.id, word } );
// Accumulate main forms // Accumulate main forms
for ( unsigned x = 0; x < activeDicts.size(); ++x ) { for ( const auto & activeDict : activeDicts ) {
sptr< Dictionary::WordSearchRequest > s = auto const s = activeDict->findHeadwordsForSynonym( gd::removeTrailingZero( word ) );
activeDicts[ x ]->findHeadwordsForSynonym( gd::removeTrailingZero( word ) );
connect( s.get(), &Dictionary::Request::finished, this, &ArticleRequest::altSearchFinished, Qt::QueuedConnection ); connect( s.get(), &Dictionary::Request::finished, this, &ArticleRequest::altSearchFinished, Qt::QueuedConnection );
@ -508,7 +507,7 @@ void ArticleRequest::altSearchFinished()
return; return;
// Check every request for finishing // 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() ) { if ( ( *i )->isFinished() ) {
// This one's finished // This one's finished
for ( size_t count = ( *i )->matchesCount(), x = 0; x < count; ++x ) 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() ); vector< wstring > altsVector( alts.begin(), alts.end() );
#ifdef QT_DEBUG #ifdef QT_DEBUG
for ( unsigned x = 0; x < altsVector.size(); ++x ) { for ( const auto & x : altsVector ) {
qDebug() << "Alt:" << QString::fromStdU32String( altsVector[ x ] ); qDebug() << "Alt:" << QString::fromStdU32String( x );
} }
#endif #endif
@ -542,12 +541,12 @@ void ArticleRequest::altSearchFinished()
if ( activeDicts.size() <= 1 ) if ( activeDicts.size() <= 1 )
articleSizeLimit = -1; // Don't collapse article if only one dictionary presented 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 { try {
sptr< Dictionary::DataRequest > r = activeDicts[ x ]->getArticle( sptr< Dictionary::DataRequest > r = activeDict->getArticle(
wordStd, wordStd,
altsVector, altsVector,
gd::removeTrailingZero( contexts.value( QString::fromStdString( activeDicts[ x ]->getId() ) ) ), gd::removeTrailingZero( contexts.value( QString::fromStdString( activeDict->getId() ) ) ),
ignoreDiacritics ); ignoreDiacritics );
connect( r.get(), &Dictionary::Request::finished, this, &ArticleRequest::bodyFinished, Qt::QueuedConnection ); connect( r.get(), &Dictionary::Request::finished, this, &ArticleRequest::bodyFinished, Qt::QueuedConnection );
@ -555,7 +554,7 @@ void ArticleRequest::altSearchFinished()
bodyRequests.push_back( r ); bodyRequests.push_back( r );
} }
catch ( std::exception & e ) { 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() );
} }
} }

View file

@ -303,15 +303,15 @@ void EpwingDictionary::loadArticle(
articleHeadword = string( headword.toUtf8().data() ); articleHeadword = string( headword.toUtf8().data() );
articleText = string( text.toUtf8().data() ); articleText = string( text.toUtf8().data() );
string prefix( "<div class=\"epwing_text\">" ); const string prefix( "<div class=\"epwing_text\">" );
articleText = prefix + articleText + "</div>"; articleText = prefix + articleText + "</div>";
} }
string Epwing::EpwingDictionary::epwing_previous_button( const int & articlePage, const int & articleOffset ) string Epwing::EpwingDictionary::epwing_previous_button( const int & articlePage, const int & articleOffset )
{ {
QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset ); const QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset );
string previousLink = R"(<p><a class="epwing_previous_page" href="gdlookup://localhost/)" string previousLink = R"(<p><a class="epwing_previous_page" href="gdlookup://localhost/)"
+ previousButton.toStdString() + "?dictionaries=" + getId() + "\">" + tr( "Previous Page" ).toStdString() + previousButton.toStdString() + "?dictionaries=" + getId() + "\">" + tr( "Previous Page" ).toStdString()
+ "</a></p>"; + "</a></p>";
@ -349,8 +349,8 @@ void EpwingDictionary::loadArticleNextPage( string & articleHeadword,
string Epwing::EpwingDictionary::epwing_next_button( const int & articlePage, const int & articleOffset ) string Epwing::EpwingDictionary::epwing_next_button( const int & articlePage, const int & articleOffset )
{ {
QString refLink = QString( "r%1At%2" ).arg( articlePage ).arg( articleOffset ); QString refLink = QString( "r%1At%2" ).arg( articlePage ).arg( articleOffset );
string nextLink = R"(<p><a class="epwing_next_page" href="gdlookup://localhost/)" + refLink.toStdString() + "?dictionaries="+getId()+"\">" string nextLink = R"(<p><a class="epwing_next_page" href="gdlookup://localhost/)" + refLink.toStdString()
+ tr( "Next Page" ).toStdString() + "</a></p>"; + "?dictionaries=" + getId() + "\">" + tr( "Next Page" ).toStdString() + "</a></p>";
return nextLink; return nextLink;
} }