mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
fix Hunspell regression related to encoding
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
Some checks are pending
SonarCloud / Build and analyze (push) Waiting to run
This commit is contained in:
parent
a1b3d76f9c
commit
ad19263423
|
@ -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 ) {
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue