Skip to content

Commit

Permalink
fix: duplicated entries in epwing dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyifang committed May 22, 2022
1 parent 435cadf commit 467b2d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
42 changes: 33 additions & 9 deletions epwing_book.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ void EpwingBook::getFirstHeadword( EpwingHeadword & head )
fixHeadword( head.headword );

EWPos epos( pos.page, pos.offset );
allHeadwordPositions[ head.headword ] = epos;
allHeadwordPositions[ head.headword ] << epos;
}

bool EpwingBook::getNextHeadword( EpwingHeadword & head )
Expand Down Expand Up @@ -881,13 +881,25 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )

if( allHeadwordPositions.contains( head.headword ) )
{
EWPos epos = allHeadwordPositions[ head.headword ];
if( pos.page != epos.first || abs( pos.offset - epos.second ) > 4 )
// existed position
bool existed = false;
foreach( EWPos epos, allHeadwordPositions[ head.headword ] )
{
if( pos.page == epos.first && abs( pos.offset - epos.second ) <= 4 )
{
existed = true;
break;
}
}
if( !existed )
{
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
else
{
allHeadwordPositions[ head.headword ] = EWPos( pos.page, pos.offset );
allHeadwordPositions[ head.headword ]<<EWPos( pos.page, pos.offset );
return true;
}
}
Expand Down Expand Up @@ -943,14 +955,26 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head )

if( allHeadwordPositions.contains( head.headword ) )
{
EWPos epos = allHeadwordPositions[ head.headword ];
if( pos.page != epos.first || abs( pos.offset - epos.second ) > 4 )
break;
// existed position
bool existed = false;
foreach( EWPos epos, allHeadwordPositions[ head.headword ] )
{
if( pos.page == epos.first && abs( pos.offset - epos.second ) <= 4 )
{
existed = true;
break;
}
}
if( !existed )
{
allHeadwordPositions[ head.headword ] << EWPos( pos.page, pos.offset );
return true;
}
}
else
{
allHeadwordPositions[ head.headword ] = EWPos( pos.page, pos.offset );
break;
allHeadwordPositions[ head.headword ]<<EWPos( pos.page, pos.offset );
return true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion epwing_book.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class EpwingBook
QStringList imageCacheList, soundsCacheList, moviesCacheList, fontsCacheList;
QMap< QString, QString > baseFontsMap, customFontsMap;
QVector< int > refPages, refOffsets;
QMap< QString, EWPos > allHeadwordPositions;
QMap< QString, QList<EWPos> > allHeadwordPositions;
QVector< EWPos > LinksQueue;
int refOpenCount, refCloseCount;
static Mutex libMutex;
Expand Down

0 comments on commit 467b2d1

Please sign in to comment.