mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
fix: code smell
This commit is contained in:
parent
c527588209
commit
f69f248c00
|
@ -226,8 +226,7 @@ std::string ArticleMaker::makeNotFoundBody( QString const & word,
|
||||||
|
|
||||||
if ( word.size() )
|
if ( word.size() )
|
||||||
result += tr( "No translation for <b>%1</b> was found in group <b>%2</b>." ).
|
result += tr( "No translation for <b>%1</b> was found in group <b>%2</b>." ).
|
||||||
arg( QString::fromUtf8( Html::escape( str.toUtf8().data() ).c_str() ) ).
|
arg( QString::fromUtf8( Html::escape( str.toUtf8().data() ).c_str() ), QString::fromUtf8( Html::escape( group.toUtf8().data() ).c_str() ) ).
|
||||||
arg( QString::fromUtf8( Html::escape( group.toUtf8().data() ).c_str() ) ).
|
|
||||||
toUtf8().data();
|
toUtf8().data();
|
||||||
else
|
else
|
||||||
result += tr( "No translation was found in group <b>%1</b>." ).
|
result += tr( "No translation was found in group <b>%1</b>." ).
|
||||||
|
|
57
epwing.cc
57
epwing.cc
|
@ -210,9 +210,9 @@ private:
|
||||||
friend class EpwingWordSearchRequest;
|
friend class EpwingWordSearchRequest;
|
||||||
|
|
||||||
friend class EpwingHeadwordsRequest;
|
friend class EpwingHeadwordsRequest;
|
||||||
string epwing_previous_button(int& articleOffset, int& articlePage);
|
string epwing_previous_button( const int& articleOffset, const int& articlePage);
|
||||||
string epwing_next_button(int& articleOffset, int& articlePage);
|
string epwing_next_button( const int& articleOffset, const int& articlePage);
|
||||||
bool readHeadword( EB_Position & pos, QString & headword );
|
bool readHeadword( const EB_Position & pos, QString & headword );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -342,17 +342,15 @@ void EpwingDictionary::loadArticle(
|
||||||
articleText = prefix + articleText + "</div>";
|
articleText = prefix + articleText + "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
string Epwing::EpwingDictionary::epwing_previous_button(int& articlePage, int& articleOffset)
|
string Epwing::EpwingDictionary::epwing_previous_button( const int& articlePage, const int& articleOffset)
|
||||||
{
|
{
|
||||||
QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset );
|
QString previousButton = QString( "p%1At%2" ).arg( articlePage ).arg( articleOffset );
|
||||||
string previousLink = "<p><a class=\"epwing_previous_page\" href=\"gdlookup://localhost/"
|
string previousLink = R"(<p><a class="epwing_previous_page" href="gdlookup://localhost/)"
|
||||||
+ previousButton.toStdString() + "\">" + tr( "Previous Page" ).toStdString() + "</a></p>";
|
+ previousButton.toStdString() + "\">" + tr( "Previous Page" ).toStdString() + "</a></p>";
|
||||||
|
|
||||||
return previousLink;
|
return previousLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void EpwingDictionary::loadArticleNextPage(string & articleHeadword, string & articleText, int & articlePage, int & articleOffset )
|
void EpwingDictionary::loadArticleNextPage(string & articleHeadword, string & articleText, int & articlePage, int & articleOffset )
|
||||||
{
|
{
|
||||||
QString headword, text;
|
QString headword, text;
|
||||||
|
@ -382,10 +380,10 @@ void EpwingDictionary::loadArticleNextPage(string & articleHeadword, string & ar
|
||||||
articleText = articleText + "</div>";
|
articleText = articleText + "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
string Epwing::EpwingDictionary::epwing_next_button(int& articlePage, 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 = "<p><a class=\"epwing_next_page\" href=\"gdlookup://localhost/" + refLink.toStdString() + "\">"
|
string nextLink = R"(<p><a class="epwing_next_page" href="gdlookup://localhost/)" + refLink.toStdString() + "\">"
|
||||||
+ tr( "Next Page" ).toStdString() + "</a></p>";
|
+ tr( "Next Page" ).toStdString() + "</a></p>";
|
||||||
|
|
||||||
return nextLink;
|
return nextLink;
|
||||||
|
@ -665,10 +663,9 @@ void EpwingArticleRequest::run()
|
||||||
|
|
||||||
vector< WordArticleLink > chain = dict.findArticles( word, ignoreDiacritics );
|
vector< WordArticleLink > chain = dict.findArticles( word, ignoreDiacritics );
|
||||||
|
|
||||||
for( unsigned x = 0; x < alts.size(); ++x )
|
for ( auto & alt : alts ) {
|
||||||
{
|
|
||||||
/// Make an additional query for each alt
|
/// Make an additional query for each alt
|
||||||
vector< WordArticleLink > altChain = dict.findArticles( alts[ x ], ignoreDiacritics );
|
vector< WordArticleLink > altChain = dict.findArticles( alt, ignoreDiacritics );
|
||||||
|
|
||||||
chain.insert( chain.end(), altChain.begin(), altChain.end() );
|
chain.insert( chain.end(), altChain.begin(), altChain.end() );
|
||||||
}
|
}
|
||||||
|
@ -685,15 +682,14 @@ void EpwingArticleRequest::run()
|
||||||
|
|
||||||
QVector< int > pages, offsets;
|
QVector< int > pages, offsets;
|
||||||
|
|
||||||
for( unsigned x = 0; x < chain.size(); ++x )
|
for ( auto & x : chain ) {
|
||||||
{
|
|
||||||
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
if ( Utils::AtomicInt::loadAcquire( isCancelled ) )
|
||||||
{
|
{
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( articlesIncluded.find( chain[ x ].articleOffset ) != articlesIncluded.end() )
|
if ( articlesIncluded.find( x.articleOffset ) != articlesIncluded.end() )
|
||||||
continue; // We already have this article in the body.
|
continue; // We already have this article in the body.
|
||||||
|
|
||||||
// Now grab that article
|
// Now grab that article
|
||||||
|
@ -703,7 +699,7 @@ void EpwingArticleRequest::run()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
dict.loadArticle( chain[ x ].articleOffset, headword, articleText, articlePage, articleOffset );
|
dict.loadArticle( x.articleOffset, headword, articleText, articlePage, articleOffset );
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
|
@ -730,7 +726,7 @@ void EpwingArticleRequest::run()
|
||||||
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
|
Folding::applySimpleCaseOnly( Utf8::decode( headword ) ),
|
||||||
pair< string, string >( headword, articleText ) ) );
|
pair< string, string >( headword, articleText ) ) );
|
||||||
|
|
||||||
articlesIncluded.insert( chain[ x ].articleOffset );
|
articlesIncluded.insert( x.articleOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpressionMatch m = RX::Epwing::refWord.match( gd::toQString( word ) );
|
QRegularExpressionMatch m = RX::Epwing::refWord.match( gd::toQString( word ) );
|
||||||
|
@ -738,8 +734,8 @@ void EpwingArticleRequest::run()
|
||||||
|
|
||||||
// Also try to find word in the built-in dictionary index
|
// Also try to find word in the built-in dictionary index
|
||||||
getBuiltInArticle( word, pages, offsets, mainArticles );
|
getBuiltInArticle( word, pages, offsets, mainArticles );
|
||||||
for( unsigned x = 0; x < alts.size(); ++x ) {
|
for ( auto & alt : alts ) {
|
||||||
getBuiltInArticle( alts[ x ], pages, offsets, alternateArticles );
|
getBuiltInArticle( alt, pages, offsets, alternateArticles );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( mainArticles.empty() && alternateArticles.empty() && !ref)
|
if ( mainArticles.empty() && alternateArticles.empty() && !ref)
|
||||||
|
@ -851,6 +847,7 @@ void EpwingDictionary::getHeadwordPos( wstring const & word_, QVector< int > & p
|
||||||
eBook.getArticlePos( gd::toQString( word_ ), pg, off );
|
eBook.getArticlePos( gd::toQString( word_ ), pg, off );
|
||||||
}
|
}
|
||||||
catch ( ... ) {
|
catch ( ... ) {
|
||||||
|
//ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1122,8 +1119,8 @@ void EpwingWordSearchRequest::findMatches()
|
||||||
|
|
||||||
Mutex::Lock _( dataMutex );
|
Mutex::Lock _( dataMutex );
|
||||||
|
|
||||||
for( int i = 0; i < headwords.size(); i++ )
|
for ( const auto & headword : headwords )
|
||||||
addMatch( gd::toWString( headwords.at( i ) ) );
|
addMatch( gd::toWString( headword ) );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1146,7 +1143,7 @@ sptr< Dictionary::WordSearchRequest > EpwingDictionary::stemmedMatch(
|
||||||
return std::make_shared<EpwingWordSearchRequest>( *this, str, minLength, (int)maxSuffixVariation,
|
return std::make_shared<EpwingWordSearchRequest>( *this, str, minLength, (int)maxSuffixVariation,
|
||||||
false, maxResults );
|
false, maxResults );
|
||||||
}
|
}
|
||||||
bool Epwing::EpwingDictionary::readHeadword( EB_Position & pos, QString & headword )
|
bool Epwing::EpwingDictionary::readHeadword( const EB_Position & pos, QString & headword )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1155,7 +1152,7 @@ bool Epwing::EpwingDictionary::readHeadword( EB_Position & pos, QString & headwo
|
||||||
eBook.fixHeadword( headword );
|
eBook.fixHeadword( headword );
|
||||||
return eBook.isHeadwordCorrect( headword ) ;
|
return eBook.isHeadwordCorrect( headword ) ;
|
||||||
}
|
}
|
||||||
catch( std::exception & e )
|
catch( std::exception & )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1275,20 +1272,18 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
vector< string > dictFiles;
|
vector< string > dictFiles;
|
||||||
QByteArray catName = QString("%1catalogs").arg(QDir::separator()).toUtf8();
|
QByteArray catName = QString("%1catalogs").arg(QDir::separator()).toUtf8();
|
||||||
|
|
||||||
for( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end();
|
for ( const auto & fileName : fileNames ) {
|
||||||
++i )
|
|
||||||
{
|
|
||||||
// Skip files other than "catalogs" to speed up the scanning
|
// Skip files other than "catalogs" to speed up the scanning
|
||||||
|
|
||||||
if ( i->size() < (unsigned)catName.size() ||
|
if ( fileName.size() < (unsigned)catName.size() ||
|
||||||
strcasecmp( i->c_str() + ( i->size() - catName.size() ), catName.data() ) != 0 )
|
strcasecmp( fileName.c_str() + ( fileName.size() - catName.size() ), catName.data() ) != 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int ndir = i->size() - catName.size();
|
int ndir = fileName.size() - catName.size();
|
||||||
if( ndir < 1 )
|
if( ndir < 1 )
|
||||||
ndir = 1;
|
ndir = 1;
|
||||||
|
|
||||||
string mainDirectory = i->substr( 0, ndir );
|
string mainDirectory = fileName.substr( 0, ndir );
|
||||||
|
|
||||||
Epwing::Book::EpwingBook dict;
|
Epwing::Book::EpwingBook dict;
|
||||||
int subBooksNumber = 0;
|
int subBooksNumber = 0;
|
||||||
|
@ -1311,7 +1306,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||||
{
|
{
|
||||||
dictFiles.clear();
|
dictFiles.clear();
|
||||||
dictFiles.push_back( mainDirectory );
|
dictFiles.push_back( mainDirectory );
|
||||||
dictFiles.push_back( *i );
|
dictFiles.push_back( fileName );
|
||||||
|
|
||||||
dict.setSubBook( sb );
|
dict.setSubBook( sb );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue