fix:code smell

This commit is contained in:
Xiao YiFang 2023-04-09 11:48:21 +08:00 committed by xiaoyifang
parent 1996af61a6
commit c472b2cb71
2 changed files with 10 additions and 14 deletions

22
mdx.cc
View file

@ -299,9 +299,9 @@ private:
void loadArticle( uint32_t offset, string & articleText, bool noFilter = false ); void loadArticle( uint32_t offset, string & articleText, bool noFilter = false );
/// Process resource links (images, audios, etc) /// 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 //@font-face
void replaceStyleInHtml( QString & id, QString & article ); void replaceStyleInHtml( QString & id, QString & article );
void replaceFontLinks( QString & id, QString & article ); void replaceFontLinks( QString & id, QString & article );
@ -739,7 +739,7 @@ void MddResourceRequest::run()
} }
// In order to prevent recursive internal redirection... // In order to prevent recursive internal redirection...
set< wstring > resourceIncluded; set< wstring, std::less<> > resourceIncluded;
for ( ;; ) for ( ;; )
{ {
@ -894,13 +894,9 @@ void MdxDictionary::loadArticle( uint32_t offset, string & articleText, bool noF
// Load record info from index // Load record info from index
MdictParser::RecordInfo recordInfo; MdictParser::RecordInfo recordInfo;
char * pRecordInfo = chunks.getBlock( offset, chunk ); const char * pRecordInfo = chunks.getBlock( offset, chunk );
memcpy( &recordInfo, pRecordInfo, sizeof( recordInfo ) ); memcpy( &recordInfo, pRecordInfo, sizeof( recordInfo ) );
// Make a sub unique id for this article
QString articleId;
articleId.setNum( ( quint64 )pRecordInfo, 16 );
QByteArray decompressed; QByteArray decompressed;
{ {
@ -923,22 +919,22 @@ void MdxDictionary::loadArticle( uint32_t offset, string & articleText, bool noF
if( !noFilter ) if( !noFilter )
{ {
article = MdictParser::substituteStylesheet( article, styleSheets ); article = MdictParser::substituteStylesheet( article, styleSheets );
article = filterResource( articleId, article ); article = filterResource( article );
} }
// articleText = article.toStdString(); // articleText = article.toStdString();
articleText = string( article.toUtf8().constData() ); articleText = string( article.toUtf8().constData() );
} }
QString & MdxDictionary::filterResource( QString const & articleId, QString & article ) QString & MdxDictionary::filterResource( QString & article )
{ {
QString id = QString::fromStdString( getId() ); QString id = QString::fromStdString( getId() );
replaceLinks( id, articleId, article ); replaceLinks( id, article );
replaceStyleInHtml( id, article); replaceStyleInHtml( id, article);
return article; return article;
} }
void MdxDictionary::replaceLinks( QString & id, const QString & articleId, QString & article ) void MdxDictionary::replaceLinks( QString & id, QString & article )
{ {
QString articleNewText; QString articleNewText;
int linkPos = 0; int linkPos = 0;
@ -1181,7 +1177,7 @@ QString MdxDictionary::getCachedFileName( QString filename )
vector< char > data; vector< char > data;
// In order to prevent recursive internal redirection... // In order to prevent recursive internal redirection...
set< wstring > resourceIncluded; set< wstring, std::less<> > resourceIncluded;
for( ;; ) { for( ;; ) {
if( !resourceIncluded.insert( resourceName ).second ) if( !resourceIncluded.insert( resourceName ).second )

View file

@ -585,7 +585,7 @@ void ArticleView::loadFinished( bool result )
webview->page()->runJavaScript( QString( "gdCheckArticlesNumber();" ) ); webview->page()->runJavaScript( QString( "gdCheckArticlesNumber();" ) );
if( !Utils::Url::queryItemValue( url, "gdanchor" ).isEmpty() ) { 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 // Find GD anchor on page
url.clear(); url.clear();