Sonnet
kspell_hspelldict.cpp
Go to the documentation of this file.00001
00023 #include "kspell_hspelldict.h"
00024 #include <kdebug.h>
00025
00026 #include <QtCore/QTextCodec>
00027
00028 using namespace Sonnet;
00029
00030 HSpellDict::HSpellDict( const QString& lang )
00031 : SpellerPlugin( lang )
00032 {
00033 int int_error = hspell_init( &m_speller, HSPELL_OPT_DEFAULT );
00034 if ( int_error == -1 ) {
00035 kDebug() << "HSpellDict::HSpellDict: Init failed";
00036
00037 codec = QTextCodec::codecForName( "iso8859-8-i" );
00038 initialized = false;
00039 } else {
00040 initialized = true;
00041 }
00042 }
00043
00044 HSpellDict::~HSpellDict()
00045 {
00046
00047 if (initialized)
00048 hspell_uninit( m_speller );
00049 }
00050
00051 bool HSpellDict::isCorrect( const QString& word ) const
00052 {
00053 kDebug() << "HSpellDict::check word = " << word;
00054 int preflen;
00055 QByteArray wordISO = codec->fromUnicode( word );
00056
00057 int correct = hspell_check_word ( m_speller,
00058 wordISO,
00059 &preflen);
00060
00061
00062 if( correct != 1 ){
00063 if( hspell_is_canonic_gimatria( wordISO ) != 0 )
00064 correct = 1;
00065 }
00066 return correct == 1;
00067 }
00068
00069 QStringList HSpellDict::suggest( const QString& word ) const
00070 {
00071 QStringList qsug;
00072 struct corlist cl;
00073 int n_sugg;
00074 corlist_init( &cl );
00075 hspell_trycorrect( m_speller, codec->fromUnicode( word ), &cl );
00076 for( n_sugg = 0; n_sugg < corlist_n( &cl ); n_sugg++){
00077 qsug.append( codec->toUnicode( corlist_str( &cl, n_sugg) ) );
00078 }
00079 corlist_free( &cl );
00080 return qsug;
00081 }
00082
00083 bool HSpellDict::storeReplacement( const QString& bad,
00084 const QString& good )
00085 {
00086
00087 kDebug() << "HSpellDict::storeReplacement: Sorry, cannot.";
00088 return false;
00089 }
00090
00091 bool HSpellDict::addToPersonal( const QString& word )
00092 {
00093
00094 kDebug() << "HSpellDict::addToPersonal: Sorry, cannot.";
00095 return false;
00096 }
00097
00098 bool HSpellDict::addToSession( const QString& word )
00099 {
00100
00101 kDebug() << "HSpellDict::addToSession: Sorry, cannot.";
00102 return false;
00103 }