fix Hunspell regression related to encoding
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run

This commit is contained in:
shenleban tongying 2024-11-26 11:18:21 -05:00
parent a1b3d76f9c
commit ad19263423
3 changed files with 10 additions and 3 deletions

View file

@ -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 ) {

View file

@ -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 );

View file

@ -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.
@ -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.
@ -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 );