[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: [PATCH] A fix for UTF-8 and string length problem in KSpell2+ASpell
From: Mashrab Kuvatov <kmashrab () sat ! physik ! uni-bremen ! de>
Date: 2005-03-18 10:46:01
Message-ID: 200503181146.11615.kmashrab () sat ! physik ! uni-bremen ! de
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hi all,
please have a look at the attached patch and possibly commit it.
All information is available at BR#87250, I did not want to re-post it here.
BTW, thanks for KDE 3.4. It is great. :-)
Cheers,
Mashrab.
--
Mashrab Kuvatov
Ph.D student
University of Bremen, IUP
Home-page: www.sat.uni-bremen.de/members/mashrab
PGP key: www.uni-bremen.de/~kmashrab/kmashrab.asc
["kspell2-aspell-utf8.patch" (text/x-diff)]
--- kspell_aspelldict.cpp 2005-02-19 15:52:45.506305552 +0100
+++ my_kspell_aspelldict.cpp 2005-02-19 16:10:22.626598840 +0100
@@ -22,6 +22,8 @@
#include <kdebug.h>
+#include <qtextcodec.h>
+
using namespace KSpell2;
ASpellDict::ASpellDict( const QString& lang )
@@ -29,6 +31,9 @@
{
m_config = new_aspell_config();
aspell_config_replace( m_config, "lang", lang.latin1() );
+ /* All communication with Aspell is done in UTF-8 */
+ /* For reference, please look at BR#87250 */
+ aspell_config_replace( m_config, "encoding", "utf-8" );
AspellCanHaveError * possible_err = new_aspell_speller( m_config );
@@ -47,15 +52,22 @@
bool ASpellDict::check( const QString& word )
{
- int correct = aspell_speller_check( m_speller, word.utf8(), word.length() );
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
+ int correct = aspell_speller_check( m_speller, word.utf8(), word.utf8().length() );
return correct;
}
QStringList ASpellDict::suggest( const QString& word )
{
+ /* Needed for Unicode conversion */
+ QTextCodec *codec = QTextCodec::codecForName("utf8");
+
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
const AspellWordList * suggestions = aspell_speller_suggest( m_speller,
word.utf8(),
- word.length() );
+ word.utf8().length() );
AspellStringEnumeration * elements = aspell_word_list_elements( suggestions );
@@ -63,7 +75,9 @@
const char * cword;
while ( (cword = aspell_string_enumeration_next( elements )) ) {
- qsug.append( cword );
+ /* Since while creating the class ASpellDict the encoding is set */
+ /* to utf-8, one has to convert output from Aspell to Unicode */
+ qsug.append( codec->toUnicode( cword ) );
}
delete_aspell_string_enumeration( elements );
@@ -82,19 +96,25 @@
bool ASpellDict::storeReplacement( const QString& bad,
const QString& good )
{
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
return aspell_speller_store_replacement( m_speller,
- bad.utf8(), bad.length(),
- good.utf8(), good.length() );
+ bad.utf8(), bad.utf8().length(),
+ good.utf8(), good.utf8().length() );
}
bool ASpellDict::addToPersonal( const QString& word )
{
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
return aspell_speller_add_to_personal( m_speller, word.utf8(),
- word.length() );
+ word.utf8().length() );
}
bool ASpellDict::addToSession( const QString& word )
{
+ /* ASpell is expecting length of a string in char representation */
+ /* word.length() != word.utf8().length() for nonlatin strings */
return aspell_speller_add_to_session( m_speller, word.utf8(),
- word.length() );
+ word.utf8().length() );
}
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic