Skip to content

Commit

Permalink
fix Hunspell regression related to encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying committed Nov 26, 2024
1 parent a1b3d76 commit ad19263
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/common/iconv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ std::string Iconv::toUtf8( char const * fromEncoding, void const * fromData, siz
return outStr.toStdString();
}

std::string Iconv::toUtf8( char const * fromEncoding, std::u32string_view str )
{
// u32string::size -> returns the number of char32_t instead of the length of bytes
return toUtf8( fromEncoding, str.data(), str.size() * sizeof( char32_t ) );
}

QString Iconv::toQString( char const * fromEncoding, void const * fromData, size_t dataSize )
{
if ( dataSize == 0 ) {
Expand Down
1 change: 1 addition & 0 deletions src/common/iconv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public:
// Converts a given block of data from the given encoding to an utf8-encoded
// string.
static std::string toUtf8( char const * fromEncoding, void const * fromData, size_t dataSize );
static std::string toUtf8( char const * fromEncoding, std::u32string_view str );

static QString toQString( char const * fromEncoding, void const * fromData, size_t dataSize );

Expand Down
6 changes: 3 additions & 3 deletions src/dict/hunspell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void HunspellArticleRequest::run()

QMutexLocker _( &hunspellMutex );

string trimmedWord_utf8 = Iconv::toUtf8( Text::utf32, trimmedWord.data(), trimmedWord.size() );
string trimmedWord_utf8 = Iconv::toUtf8( Text::utf32_le, trimmedWord );

if ( hunspell.spell( trimmedWord_utf8 ) ) {
// Good word -- no spelling suggestions then.
Expand Down Expand Up @@ -361,7 +361,7 @@ QList< std::u32string > suggest( std::u32string & word, QMutex & hunspellMutex,
try {
QMutexLocker _( &hunspellMutex );

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

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

QMutexLocker _( &hunspellMutex );

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

QMutexLocker _( &dataMutex );
Expand Down

0 comments on commit ad19263

Please sign in to comment.