Skip to content

Commit

Permalink
clean: delete Hunspell::encodeToHunspell which is a synonym of utf32-…
Browse files Browse the repository at this point in the history
…>utf8
  • Loading branch information
shenlebantongying committed Nov 24, 2024
1 parent 0c42c30 commit 52a9427
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions src/dict/hunspell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ class HunspellDictionary: public Dictionary::Class
// QMutex hunspellMutex;
};

/// Encodes the given string to be passed to the hunspell object. May throw
/// Iconv::Ex
string encodeToHunspell( Hunspell &, std::u32string const & );

/// Decodes the given string returned by the hunspell object. May throw
/// Iconv::Ex
std::u32string decodeFromHunspell( Hunspell &, char const * );
Expand Down Expand Up @@ -211,15 +207,15 @@ void HunspellArticleRequest::run()

QMutexLocker _( &hunspellMutex );

string encodedWord = encodeToHunspell( hunspell, trimmedWord );
string trimmedWord_utf8 = Iconv::toUtf8( Iconv::GdWchar, trimmedWord.data(), trimmedWord.size() );

if ( hunspell.spell( encodedWord ) ) {
if ( hunspell.spell( trimmedWord_utf8 ) ) {
// Good word -- no spelling suggestions then.
finish();
return;
}

suggestions = hunspell.suggest( encodedWord );
suggestions = hunspell.suggest( trimmedWord_utf8 );
if ( !suggestions.empty() ) {
// There were some suggestions made for us. Make an appropriate output.

Expand Down Expand Up @@ -362,14 +358,10 @@ QList< std::u32string > suggest( std::u32string & word, QMutex & hunspellMutex,
{
QList< std::u32string > result;

vector< string > suggestions;

try {
QMutexLocker _( &hunspellMutex );

string encodedWord = encodeToHunspell( hunspell, word );

suggestions = hunspell.analyze( encodedWord );
auto suggestions = hunspell.analyze( Iconv::toUtf8( Iconv::GdWchar, word.data(), word.size() ) );
if ( !suggestions.empty() ) {
// There were some suggestions made for us. Make an appropriate output.

Expand Down Expand Up @@ -472,9 +464,7 @@ void HunspellPrefixMatchRequest::run()

QMutexLocker _( &hunspellMutex );

string encodedWord = encodeToHunspell( hunspell, trimmedWord );

if ( hunspell.spell( encodedWord ) ) {
if ( hunspell.spell( Iconv::toUtf8( Iconv::GdWchar, trimmedWord.data(), trimmedWord.size() ) ) ) {
// Known word -- add it to the result

QMutexLocker _( &dataMutex );
Expand Down Expand Up @@ -589,24 +579,6 @@ void getSuggestionsForExpression( std::u32string const & expression,
}
}

string encodeToHunspell( Hunspell & hunspell, std::u32string const & str )
{
Iconv conv( Iconv::GdWchar );

void const * in = str.data();
size_t inLeft = str.size() * sizeof( char32_t );

vector< char > result( str.size() * 4 + 1 ); // +1 isn't actually needed,
// but then iconv complains on empty
// words

void * out = &result.front();
size_t outLeft = result.size();

QString convStr = conv.convert( in, inLeft );
return convStr.toStdString();
}

std::u32string decodeFromHunspell( Hunspell & hunspell, char const * str )
{
Iconv conv( hunspell.get_dic_encoding() );
Expand Down

0 comments on commit 52a9427

Please sign in to comment.