mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Epwing: Handle different encodings while search via libeb engine
This commit is contained in:
parent
980be6ae3b
commit
f3134be4c4
|
@ -999,7 +999,7 @@ bool EpwingBook::isHeadwordCorrect( QString const & headword )
|
|||
if( ( book.character_code == EB_CHARCODE_JISX0208 || book.character_code == EB_CHARCODE_JISX0208_GB2312 )
|
||||
&& codec_Euc )
|
||||
buf = codec_Euc->fromUnicode( headword );
|
||||
else
|
||||
|
||||
if( book.character_code == EB_CHARCODE_JISX0208_GB2312 && codec_GB )
|
||||
buf2 = codec_GB->fromUnicode( headword );
|
||||
|
||||
|
@ -1754,7 +1754,22 @@ QByteArray EpwingBook::handleReference( EB_Hook_Code code, const unsigned int *
|
|||
|
||||
bool EpwingBook::getMatches( QString word, QVector< QString > & matches )
|
||||
{
|
||||
QByteArray bword = codecEuc()->fromUnicode( word );
|
||||
QByteArray bword, bword2;
|
||||
EB_Hit hits[ HitsBufferSize ];
|
||||
int hitCount = 0;
|
||||
|
||||
if( book.character_code == EB_CHARCODE_ISO8859_1 && codec_ISO )
|
||||
bword = codec_ISO->fromUnicode( word );
|
||||
else
|
||||
if( ( book.character_code == EB_CHARCODE_JISX0208 || book.character_code == EB_CHARCODE_JISX0208_GB2312 )
|
||||
&& codec_Euc )
|
||||
bword = codec_Euc->fromUnicode( word );
|
||||
|
||||
if( book.character_code == EB_CHARCODE_JISX0208_GB2312 && codec_GB )
|
||||
bword2 = codec_GB->fromUnicode( word );
|
||||
|
||||
if( !bword.isEmpty() )
|
||||
{
|
||||
EB_Error_Code ret = eb_search_word( &book, bword.data() );
|
||||
if( ret != EB_SUCCESS )
|
||||
{
|
||||
|
@ -1774,6 +1789,28 @@ bool EpwingBook::getMatches( QString word, QVector< QString > & matches )
|
|||
error_string.toUtf8().data() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( hitCount == 0 && !bword2.isEmpty() )
|
||||
{
|
||||
EB_Error_Code ret = eb_search_word( &book, bword2.data() );
|
||||
if( ret != EB_SUCCESS )
|
||||
{
|
||||
setErrorString( "eb_search_word", ret );
|
||||
gdWarning( "Epwing word search error: %s",
|
||||
error_string.toUtf8().data() );
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = eb_hit_list( &book, 10, hits, &hitCount );
|
||||
if( ret != EB_SUCCESS )
|
||||
{
|
||||
setErrorString( "eb_hit_list", ret );
|
||||
gdWarning( "Epwing word search error: %s",
|
||||
error_string.toUtf8().data() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QVector< int > pages, offsets;
|
||||
|
||||
|
@ -1807,7 +1844,22 @@ bool EpwingBook::getMatches( QString word, QVector< QString > & matches )
|
|||
|
||||
bool EpwingBook::getArticlePos( QString word, QVector< int > & pages, QVector< int > & offsets )
|
||||
{
|
||||
QByteArray bword = codecEuc()->fromUnicode( word );
|
||||
QByteArray bword, bword2;
|
||||
EB_Hit hits[ HitsBufferSize ];
|
||||
int hitCount = 0;
|
||||
|
||||
if( book.character_code == EB_CHARCODE_ISO8859_1 && codec_ISO )
|
||||
bword = codec_ISO->fromUnicode( word );
|
||||
else
|
||||
if( ( book.character_code == EB_CHARCODE_JISX0208 || book.character_code == EB_CHARCODE_JISX0208_GB2312 )
|
||||
&& codec_Euc )
|
||||
bword = codec_Euc->fromUnicode( word );
|
||||
|
||||
if( book.character_code == EB_CHARCODE_JISX0208_GB2312 && codec_GB )
|
||||
bword2 = codec_GB->fromUnicode( word );
|
||||
|
||||
if( !bword.isEmpty() )
|
||||
{
|
||||
EB_Error_Code ret = eb_search_exactword( &book, bword.data() );
|
||||
if( ret != EB_SUCCESS )
|
||||
{
|
||||
|
@ -1817,8 +1869,26 @@ bool EpwingBook::getArticlePos( QString word, QVector< int > & pages, QVector< i
|
|||
return false;
|
||||
}
|
||||
|
||||
EB_Hit hits[ HitsBufferSize ];
|
||||
int hitCount;
|
||||
ret = eb_hit_list( &book, HitsBufferSize, hits, &hitCount );
|
||||
if( ret != EB_SUCCESS )
|
||||
{
|
||||
setErrorString( "eb_hit_list", ret );
|
||||
gdWarning( "Epwing word search error: %s",
|
||||
error_string.toUtf8().data() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( hitCount == 0 && !bword2.isEmpty() )
|
||||
{
|
||||
EB_Error_Code ret = eb_search_exactword( &book, bword2.data() );
|
||||
if( ret != EB_SUCCESS )
|
||||
{
|
||||
setErrorString( "eb_search_word", ret );
|
||||
gdWarning( "Epwing word search error: %s",
|
||||
error_string.toUtf8().data() );
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = eb_hit_list( &book, HitsBufferSize, hits, &hitCount );
|
||||
if( ret != EB_SUCCESS )
|
||||
|
@ -1828,6 +1898,7 @@ bool EpwingBook::getArticlePos( QString word, QVector< int > & pages, QVector< i
|
|||
error_string.toUtf8().data() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for( int i = 0; i < hitCount; i++ )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue