clean code:remove qmake CONFIG 'old_hunspell' that means libhunspell > 1.5 from now on.

This commit is contained in:
xiaoyifang 2022-01-21 16:16:22 +08:00
parent b127144b18
commit f0d0a56ecc
3 changed files with 1 additions and 72 deletions

View file

@ -38,7 +38,7 @@ make sure that `qmake` is from Qt 5 installation. If not, you can try
finding it at a path like `/usr/lib/x86_64-linux-gnu/qt5/bin/qmake`. finding it at a path like `/usr/lib/x86_64-linux-gnu/qt5/bin/qmake`.
Alternatively, you might want to load `goldendict.pro` file from within Qt Creator, especially on Windows. Alternatively, you might want to load `goldendict.pro` file from within Qt Creator, especially on Windows.
Note: To compile with `libhunspell` older than 1.5 pass `"CONFIG+=old_hunspell"` to `qmake`. Note: `libhunspell` version > 1.5.
### Building with Chinese conversion support ### Building with Chinese conversion support

View file

@ -578,10 +578,6 @@ CONFIG( chinese_conversion_support ) {
} }
} }
CONFIG( old_hunspell ) {
DEFINES += OLD_HUNSPELL_INTERFACE
}
RESOURCES += resources.qrc \ RESOURCES += resources.qrc \
flags.qrc flags.qrc
TRANSLATIONS += locale/ru_RU.ts \ TRANSLATIONS += locale/ru_RU.ts \

View file

@ -245,13 +245,7 @@ void HunspellArticleRequest::run()
return; return;
} }
#ifdef OLD_HUNSPELL_INTERFACE
// We'd need to free this if it gets allocated and an exception shows up
char ** suggestions = 0;
int suggestionsCount = 0;
#else
vector< string > suggestions; vector< string > suggestions;
#endif
try try
{ {
@ -268,24 +262,15 @@ void HunspellArticleRequest::run()
string encodedWord = encodeToHunspell( hunspell, trimmedWord ); string encodedWord = encodeToHunspell( hunspell, trimmedWord );
#ifdef OLD_HUNSPELL_INTERFACE
if ( hunspell.spell( encodedWord.c_str() ) )
#else
if ( hunspell.spell( encodedWord ) ) if ( hunspell.spell( encodedWord ) )
#endif
{ {
// Good word -- no spelling suggestions then. // Good word -- no spelling suggestions then.
finish(); finish();
return; return;
} }
#ifdef OLD_HUNSPELL_INTERFACE
suggestionsCount = hunspell.suggest( &suggestions, encodedWord.c_str() );
if ( suggestionsCount )
#else
suggestions = hunspell.suggest( encodedWord ); suggestions = hunspell.suggest( encodedWord );
if ( !suggestions.empty() ) if ( !suggestions.empty() )
#endif
{ {
// There were some suggestions made for us. Make an appropriate output. // There were some suggestions made for us. Make an appropriate output.
@ -294,15 +279,9 @@ void HunspellArticleRequest::run()
wstring lowercasedWord = Folding::applySimpleCaseOnly( word ); wstring lowercasedWord = Folding::applySimpleCaseOnly( word );
#ifdef OLD_HUNSPELL_INTERFACE
for( int x = 0; x < suggestionsCount; ++x )
{
wstring suggestion = decodeFromHunspell( hunspell, suggestions[ x ] );
#else
for( vector< string >::size_type x = 0; x < suggestions.size(); ++x ) for( vector< string >::size_type x = 0; x < suggestions.size(); ++x )
{ {
wstring suggestion = decodeFromHunspell( hunspell, suggestions[ x ].c_str() ); wstring suggestion = decodeFromHunspell( hunspell, suggestions[ x ].c_str() );
#endif
if ( Folding::applySimpleCaseOnly( suggestion ) == lowercasedWord ) if ( Folding::applySimpleCaseOnly( suggestion ) == lowercasedWord )
{ {
@ -312,9 +291,6 @@ void HunspellArticleRequest::run()
finish(); finish();
#ifdef OLD_HUNSPELL_INTERFACE
hunspell.free_list( &suggestions, suggestionsCount );
#endif
return; return;
} }
string suggestionUtf8 = Utf8::encode( suggestion ); string suggestionUtf8 = Utf8::encode( suggestion );
@ -323,11 +299,7 @@ void HunspellArticleRequest::run()
result += Html::escape( suggestionUtf8 ) + "\">"; result += Html::escape( suggestionUtf8 ) + "\">";
result += Html::escape( suggestionUtf8 ) + "</a>"; result += Html::escape( suggestionUtf8 ) + "</a>";
#ifdef OLD_HUNSPELL_INTERFACE
if ( x != suggestionsCount - 1 )
#else
if ( x != suggestions.size() - 1 ) if ( x != suggestions.size() - 1 )
#endif
result += ", "; result += ", ";
} }
@ -351,15 +323,6 @@ void HunspellArticleRequest::run()
gdWarning( "Hunspell: error: %s\n", e.what() ); gdWarning( "Hunspell: error: %s\n", e.what() );
} }
#ifdef OLD_HUNSPELL_INTERFACE
if ( suggestions )
{
Mutex::Lock _( hunspellMutex );
hunspell.free_list( &suggestions, suggestionsCount );
}
#endif
finish(); finish();
} }
@ -487,13 +450,7 @@ QVector< wstring > suggest( wstring & word, Mutex & hunspellMutex, Hunspell & hu
{ {
QVector< wstring > result; QVector< wstring > result;
#ifdef OLD_HUNSPELL_INTERFACE
// We'd need to free this if it gets allocated and an exception shows up
char ** suggestions = 0;
int suggestionsCount = 0;
#else
vector< string > suggestions; vector< string > suggestions;
#endif
try try
{ {
@ -501,13 +458,8 @@ QVector< wstring > suggest( wstring & word, Mutex & hunspellMutex, Hunspell & hu
string encodedWord = encodeToHunspell( hunspell, word ); string encodedWord = encodeToHunspell( hunspell, word );
#ifdef OLD_HUNSPELL_INTERFACE
suggestionsCount = hunspell.analyze( &suggestions, encodedWord.c_str() );
if ( suggestionsCount )
#else
suggestions = hunspell.analyze( encodedWord ); suggestions = hunspell.analyze( encodedWord );
if ( !suggestions.empty() ) if ( !suggestions.empty() )
#endif
{ {
// There were some suggestions made for us. Make an appropriate output. // There were some suggestions made for us. Make an appropriate output.
@ -515,15 +467,9 @@ QVector< wstring > suggest( wstring & word, Mutex & hunspellMutex, Hunspell & hu
static QRegExp cutStem( "^\\s*st:(((\\s+(?!\\w{2}:)(?!-)(?!\\+))|\\S+)+)" ); static QRegExp cutStem( "^\\s*st:(((\\s+(?!\\w{2}:)(?!-)(?!\\+))|\\S+)+)" );
#ifdef OLD_HUNSPELL_INTERFACE
for( int x = 0; x < suggestionsCount; ++x )
{
QString suggestion = gd::toQString( decodeFromHunspell( hunspell, suggestions[ x ] ) );
#else
for( vector< string >::size_type x = 0; x < suggestions.size(); ++x ) for( vector< string >::size_type x = 0; x < suggestions.size(); ++x )
{ {
QString suggestion = gd::toQString( decodeFromHunspell( hunspell, suggestions[ x ].c_str() ) ); QString suggestion = gd::toQString( decodeFromHunspell( hunspell, suggestions[ x ].c_str() ) );
#endif
// Strip comments // Strip comments
int n = suggestion.indexOf( '#' ); int n = suggestion.indexOf( '#' );
@ -552,15 +498,6 @@ QVector< wstring > suggest( wstring & word, Mutex & hunspellMutex, Hunspell & hu
gdWarning( "Hunspell: charset conversion error, no processing's done: %s\n", e.what() ); gdWarning( "Hunspell: charset conversion error, no processing's done: %s\n", e.what() );
} }
#ifdef OLD_HUNSPELL_INTERFACE
if ( suggestions )
{
Mutex::Lock _( hunspellMutex );
hunspell.free_list( &suggestions, suggestionsCount );
}
#endif
return result; return result;
} }
@ -662,11 +599,7 @@ void HunspellPrefixMatchRequest::run()
string encodedWord = encodeToHunspell( hunspell, trimmedWord ); string encodedWord = encodeToHunspell( hunspell, trimmedWord );
#ifdef OLD_HUNSPELL_INTERFACE
if ( hunspell.spell( encodedWord.c_str() ) )
#else
if ( hunspell.spell( encodedWord ) ) if ( hunspell.spell( encodedWord ) )
#endif
{ {
// Known word -- add it to the result // Known word -- add it to the result