Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from deprecated Hunspell API #160

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/SpellCheckers/HunspellChecker/hunspellchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QRegularExpression>

#include <memory>
#include <string>

namespace {
/*! \brief Wrapper around Hunspell object */
Expand Down Expand Up @@ -77,13 +78,11 @@ class HunspellWrapper
QStringList suggestionsList;
QMutexLocker lock( &d_mutex );
HunspellPtr hunspell = d_hunspell;
char** suggestions;
int numSuggestions = d_hunspell->suggest( &suggestions, encode( word ) );
suggestionsList.reserve( numSuggestions );
for( int i = 0; i < numSuggestions; ++i ) {
suggestionsList << decode( suggestions[i] );
std::vector<std::string> suggestions = d_hunspell->suggest( encode( word ) );
suggestionsList.reserve( suggestions.size() );
for ( const std::string& s : suggestions ) {
suggestionsList << decode( s );
}
hunspell->free_list( &suggestions, numSuggestions );
return suggestionsList;
}
/*! \brief Add the given word to the Hunspell object.
Expand All @@ -96,7 +95,7 @@ class HunspellWrapper
{
QMutexLocker lock( &d_mutex );
HunspellPtr hunspell = d_hunspell;
d_hunspell->add( encode( word ).constData() );
d_hunspell->add( encode( word ) );
}

private:
Expand All @@ -109,12 +108,12 @@ class HunspellWrapper
*
* If the codec is not set or valid the word is converted to
* its Latin-1 representation. */
QByteArray encode( const QString& word ) const
std::string encode( const QString& word ) const
{
if( d_codec != nullptr ) {
return d_codec->fromUnicode( word );
return d_codec->fromUnicode( word ).toStdString();
}
return word.toLatin1();
return word.toLatin1().toStdString();
}

/*! \brief Decode a word from the encoding of the selected dictionary.
Expand All @@ -125,10 +124,10 @@ class HunspellWrapper
*
* If the codec is not set or invalid the word is converted to
* its Latin-1 representation. */
QString decode( const QByteArray& word ) const
QString decode( const std::string& word ) const
{
if( d_codec != nullptr ) {
return d_codec->toUnicode( word );
return d_codec->toUnicode( word.c_str(), word.size() );
}
return QLatin1String( word );
}
Expand Down