kspell_hspelldict.cpp

00001 
00023 #include "kspell_hspelldict.h"
00024 #include <kdebug.h>
00025 
00026 #include <qtextcodec.h>
00027 
00028 using namespace KSpell2;
00029 
00030 HSpellDict::HSpellDict( const QString& lang )
00031     : Dictionary( lang )
00032 {
00033    int int_error = hspell_init( &m_speller, HSPELL_OPT_DEFAULT );
00034    if ( int_error == -1 )
00035       kdDebug() << "HSpellDict::HSpellDict: Init failed" << endl;
00036     /* hspell understans only iso8859-8-i            */
00037     codec = QTextCodec::codecForName( "iso8859-8-i" );
00038 }
00039 
00040 HSpellDict::~HSpellDict()
00041 {
00042     /* It exists in =< hspell-0.8 */
00043     hspell_uninit( m_speller );
00044 }
00045 
00046 bool HSpellDict::check( const QString& word )
00047 {
00048     kdDebug() << "HSpellDict::check word = " << word <<endl;
00049     int preflen;
00050     QCString wordISO = codec->fromUnicode( word );
00051     /* returns 1 if the word is correct, 0 otherwise */
00052     int correct = hspell_check_word ( m_speller,
00053                               wordISO,
00054                                       &preflen); //this going to be removed
00055                                                  //in next hspell releases
00056     /* I do not really understand what gimatria is   */
00057     if( correct != 1 ){
00058         if( hspell_is_canonic_gimatria( wordISO ) != 0 )
00059     correct = 1;
00060     }
00061     return correct == 1;
00062 }
00063 
00064 QStringList HSpellDict::suggest( const QString& word )
00065 {
00066     QStringList qsug;
00067     struct corlist cl;
00068     int n_sugg;
00069     corlist_init( &cl );
00070     hspell_trycorrect( m_speller, codec->fromUnicode( word ), &cl );
00071     for( n_sugg = 0; n_sugg < corlist_n( &cl ); n_sugg++){
00072         qsug.append( codec->toUnicode( corlist_str( &cl, n_sugg) ) );
00073     }
00074     corlist_free( &cl );
00075     return qsug;
00076 }
00077 
00078 bool HSpellDict::checkAndSuggest( const QString& word,
00079                                   QStringList& suggestions )
00080 {
00081     bool c = check( word );
00082     if( c )
00083         suggestions = suggest( word );
00084     return c;
00085 }
00086 
00087 bool HSpellDict::storeReplacement( const QString& bad,
00088                                    const QString& good )
00089 {
00090     // hspell-0.9 cannot do this
00091     kdDebug() << "HSpellDict::storeReplacement: Sorry, cannot." << endl; 
00092     return false;
00093 }
00094 
00095 bool HSpellDict::addToPersonal( const QString& word )
00096 {
00097     // hspell-0.9 cannot do this
00098     kdDebug() << "HSpellDict::addToPersonal: Sorry, cannot." << endl; 
00099     return false;
00100 }
00101 
00102 bool HSpellDict::addToSession( const QString& word )
00103 {
00104     // hspell-0.9 cannot do this
00105     kdDebug() << "HSpellDict::addToSession: Sorry, cannot." << endl; 
00106     return false;
00107 }
KDE Home | KDE Accessibility Home | Description of Access Keys