• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdespell2
 

tdespell2

  • tdespell2
  • plugins
  • aspell
tdespell_aspelldict.cpp
1 
21 #include "tdespell_aspelldict.h"
22 
23 #include <kdebug.h>
24 
25 #include <tqtextcodec.h>
26 
27 using namespace KSpell2;
28 
29 ASpellDict::ASpellDict( const TQString& lang )
30  : Dictionary( lang )
31 {
32  m_config = new_aspell_config();
33  aspell_config_replace( m_config, "lang", lang.latin1() );
34  /* All communication with Aspell is done in UTF-8 */
35  /* For reference, please look at BR#87250 */
36  aspell_config_replace( m_config, "encoding", "utf-8" );
37 
38  AspellCanHaveError * possible_err = new_aspell_speller( m_config );
39 
40  if ( aspell_error_number( possible_err ) != 0 )
41  kdDebug()<< "Error : "<< aspell_error_message( possible_err ) <<endl;
42  else
43  m_speller = to_aspell_speller( possible_err );
44 
45 }
46 
47 ASpellDict::~ASpellDict()
48 {
49  delete_aspell_speller( m_speller );
50  delete_aspell_config( m_config );
51 }
52 
53 bool ASpellDict::check( const TQString& word )
54 {
55  /* ASpell is expecting length of a string in char representation */
56  /* word.length() != word.utf8().length() for nonlatin strings */
57  int correct = aspell_speller_check( m_speller, word.utf8(), word.utf8().length() );
58  return correct;
59 }
60 
61 TQStringList ASpellDict::suggest( const TQString& word )
62 {
63  /* Needed for Unicode conversion */
64  TQTextCodec *codec = TQTextCodec::codecForName("utf8");
65 
66  /* ASpell is expecting length of a string in char representation */
67  /* word.length() != word.utf8().length() for nonlatin strings */
68  const AspellWordList * suggestions = aspell_speller_suggest( m_speller,
69  word.utf8(),
70  word.utf8().length() );
71 
72  AspellStringEnumeration * elements = aspell_word_list_elements( suggestions );
73 
74  TQStringList qsug;
75  const char * cword;
76 
77  while ( (cword = aspell_string_enumeration_next( elements )) ) {
78  /* Since while creating the class ASpellDict the encoding is set */
79  /* to utf-8, one has to convert output from Aspell to Unicode */
80  qsug.append( codec->toUnicode( cword ) );
81  }
82 
83  delete_aspell_string_enumeration( elements );
84  return qsug;
85 }
86 
87 bool ASpellDict::checkAndSuggest( const TQString& word,
88  TQStringList& suggestions )
89 {
90  bool c = check( word );
91  if ( c )
92  suggestions = suggest( word );
93  return c;
94 }
95 
96 bool ASpellDict::storeReplacement( const TQString& bad,
97  const TQString& good )
98 {
99  /* ASpell is expecting length of a string in char representation */
100  /* word.length() != word.utf8().length() for nonlatin strings */
101  return aspell_speller_store_replacement( m_speller,
102  bad.utf8(), bad.utf8().length(),
103  good.utf8(), good.utf8().length() );
104 }
105 
106 bool ASpellDict::addToPersonal( const TQString& word )
107 {
108  kdDebug() << "ASpellDict::addToPersonal: word = " << word << endl;
109  /* ASpell is expecting length of a string in char representation */
110  /* word.length() != word.utf8().length() for nonlatin strings */
111  aspell_speller_add_to_personal( m_speller, word.utf8(),
112  word.utf8().length() );
113  /* Add is not enough, one has to save it. This is not documented */
114  /* in ASpell's API manual. I found it in */
115  /* aspell-0.60.2/example/example-c.c */
116  return aspell_speller_save_all_word_lists( m_speller );
117 }
118 
119 bool ASpellDict::addToSession( const TQString& word )
120 {
121  /* ASpell is expecting length of a string in char representation */
122  /* word.length() != word.utf8().length() for nonlatin strings */
123  return aspell_speller_add_to_session( m_speller, word.utf8(),
124  word.utf8().length() );
125 }
ASpellDict::check
virtual bool check(const TQString &word)
Checks the given word.
Definition: tdespell_aspelldict.cpp:53
ASpellDict::storeReplacement
virtual bool storeReplacement(const TQString &bad, const TQString &good)
Stores user defined good replacement for the bad word.
Definition: tdespell_aspelldict.cpp:96
ASpellDict::addToSession
virtual bool addToSession(const TQString &word)
Adds word to the words recognizable in the current session.
Definition: tdespell_aspelldict.cpp:119
ASpellDict::addToPersonal
virtual bool addToPersonal(const TQString &word)
Adds word to the list of of personal words.
Definition: tdespell_aspelldict.cpp:106
ASpellDict::suggest
virtual TQStringList suggest(const TQString &word)
Fetches suggestions for the word.
Definition: tdespell_aspelldict.cpp:61
ASpellDict::checkAndSuggest
virtual bool checkAndSuggest(const TQString &word, TQStringList &suggestions)
Checks the word and fetches suggestions for it.
Definition: tdespell_aspelldict.cpp:87
KSpell2::Dictionary
Class is returned by from Broker.
Definition: dictionary.h:37
KSpell2
tdespell_hspellclient.h
Definition: backgroundchecker.h:29

tdespell2

Skip menu "tdespell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.9.1
This website is maintained by Timothy Pearson.