From c472b2cb713a0a7638ee275ecc7067b2f780ac35 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Sun, 9 Apr 2023 11:48:21 +0800 Subject: [PATCH] fix:code smell --- mdx.cc | 22 +++++++++------------- src/ui/articleview.cpp | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/mdx.cc b/mdx.cc index 9efd3676..18b58e3f 100644 --- a/mdx.cc +++ b/mdx.cc @@ -299,9 +299,9 @@ private: void loadArticle( uint32_t offset, string & articleText, bool noFilter = false ); /// Process resource links (images, audios, etc) - QString & filterResource( QString const & articleId, QString & article ); + QString & filterResource( QString & article ); - void replaceLinks( QString & id, const QString & articleId, QString & article ); + void replaceLinks( QString & id, QString & article ); //@font-face void replaceStyleInHtml( QString & id, QString & article ); void replaceFontLinks( QString & id, QString & article ); @@ -739,7 +739,7 @@ void MddResourceRequest::run() } // In order to prevent recursive internal redirection... - set< wstring > resourceIncluded; + set< wstring, std::less<> > resourceIncluded; for ( ;; ) { @@ -894,13 +894,9 @@ void MdxDictionary::loadArticle( uint32_t offset, string & articleText, bool noF // Load record info from index MdictParser::RecordInfo recordInfo; - char * pRecordInfo = chunks.getBlock( offset, chunk ); + const char * pRecordInfo = chunks.getBlock( offset, chunk ); memcpy( &recordInfo, pRecordInfo, sizeof( recordInfo ) ); - // Make a sub unique id for this article - QString articleId; - articleId.setNum( ( quint64 )pRecordInfo, 16 ); - QByteArray decompressed; { @@ -923,22 +919,22 @@ void MdxDictionary::loadArticle( uint32_t offset, string & articleText, bool noF if( !noFilter ) { article = MdictParser::substituteStylesheet( article, styleSheets ); - article = filterResource( articleId, article ); + article = filterResource( article ); } // articleText = article.toStdString(); articleText = string( article.toUtf8().constData() ); } -QString & MdxDictionary::filterResource( QString const & articleId, QString & article ) +QString & MdxDictionary::filterResource( QString & article ) { QString id = QString::fromStdString( getId() ); - replaceLinks( id, articleId, article ); + replaceLinks( id, article ); replaceStyleInHtml( id, article); return article; } -void MdxDictionary::replaceLinks( QString & id, const QString & articleId, QString & article ) +void MdxDictionary::replaceLinks( QString & id, QString & article ) { QString articleNewText; int linkPos = 0; @@ -1181,7 +1177,7 @@ QString MdxDictionary::getCachedFileName( QString filename ) vector< char > data; // In order to prevent recursive internal redirection... - set< wstring > resourceIncluded; + set< wstring, std::less<> > resourceIncluded; for( ;; ) { if( !resourceIncluded.insert( resourceName ).second ) diff --git a/src/ui/articleview.cpp b/src/ui/articleview.cpp index c225aa79..11fe2e59 100644 --- a/src/ui/articleview.cpp +++ b/src/ui/articleview.cpp @@ -585,7 +585,7 @@ void ArticleView::loadFinished( bool result ) webview->page()->runJavaScript( QString( "gdCheckArticlesNumber();" ) ); if( !Utils::Url::queryItemValue( url, "gdanchor" ).isEmpty() ) { - QString anchor = QUrl::fromPercentEncoding( Utils::Url::encodedQueryItemValue( url, "gdanchor" ) ); + const QString anchor = QUrl::fromPercentEncoding( Utils::Url::encodedQueryItemValue( url, "gdanchor" ) ); // Find GD anchor on page url.clear();