3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Kevin Atkinson
9 * Full author contact details are available in file CREDITS.
16 #define USE_ORIGINAL_MANAGER_FUNCS 1
17 // new aspell pspell missing extern "C"
19 #include <pspell/pspell.h>
23 #include "WordLangTuple.h"
25 #include <boost/assert.hpp>
34 PSpell::PSpell(BufferParams const &, string const & lang)
35 : els(0), spell_error_object(0)
38 lyxerr[Debug::GUI] << "created pspell" << endl;
44 lyxerr[Debug::GUI] << "killed pspell" << endl;
46 if (spell_error_object) {
47 delete_pspell_can_have_error(spell_error_object);
48 spell_error_object = 0;
52 delete_pspell_string_emulation(els);
54 Managers::iterator it = managers_.begin();
55 Managers::iterator end = managers_.end();
57 for (; it != end; ++it) {
58 pspell_manager_save_all_word_lists(it->second.manager);
59 delete_pspell_manager(it->second.manager);
60 delete_pspell_config(it->second.config);
65 void PSpell::addManager(string const & lang)
67 PspellConfig * config = new_pspell_config();
68 pspell_config_replace(config, "language-tag", lang.c_str());
69 PspellCanHaveError * err = new_pspell_manager(config);
70 if (spell_error_object)
71 delete_pspell_can_have_error(spell_error_object);
72 spell_error_object = 0;
74 if (pspell_error_number(err) == 0) {
76 m.manager = to_pspell_manager(err);
80 spell_error_object = err;
85 enum PSpell::Result PSpell::check(WordLangTuple const & word)
87 Result res = UNKNOWN_WORD;
89 Managers::iterator it = managers_.find(word.lang_code());
90 if (it == managers_.end()) {
91 addManager(word.lang_code());
92 it = managers_.find(word.lang_code());
94 if (it == managers_.end())
98 PspellManager * m = it->second.manager;
100 int word_ok = pspell_manager_check(m, word.word().c_str());
101 BOOST_ASSERT(word_ok != -1);
106 PspellWordList const * sugs =
107 pspell_manager_suggest(m, word.word().c_str());
108 BOOST_ASSERT(sugs != 0);
109 els = pspell_word_list_elements(sugs);
110 if (pspell_word_list_empty(sugs))
113 res = SUGGESTED_WORDS;
119 void PSpell::insert(WordLangTuple const & word)
121 Managers::iterator it = managers_.find(word.lang_code());
122 if (it != managers_.end())
123 pspell_manager_add_to_personal(it->second.manager, word.word().c_str());
127 void PSpell::accept(WordLangTuple const & word)
129 Managers::iterator it = managers_.find(word.lang_code());
130 if (it != managers_.end())
131 pspell_manager_add_to_session(it->second.manager, word.word().c_str());
135 string const PSpell::nextMiss()
137 char const * str = 0;
140 str = pspell_string_emulation_next(els);
147 docstring const PSpell::error()
149 char const * err = 0;
151 if (spell_error_object && pspell_error_number(spell_error_object) != 0) {
152 err = pspell_error_message(spell_error_object);
156 // FIXME UNICODE: err is not in UTF8, but probably the locale encoding
157 return from_utf8(err);