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 #include "support/LAssert.h"
21 #include "aspell_local.h"
22 #include "WordLangTuple.h"
25 using namespace lyx::support;
29 ASpell::ASpell(BufferParams const &, string const & lang)
30 : els(0), spell_error_object(0)
38 if (spell_error_object) {
39 delete_aspell_can_have_error(spell_error_object);
40 spell_error_object = 0;
44 delete_aspell_string_enumeration(els);
46 Spellers::iterator it = spellers_.begin();
47 Spellers::iterator end = spellers_.end();
49 for (; it != end; ++it) {
50 aspell_speller_save_all_word_lists(it->second.speller);
51 delete_aspell_speller(it->second.speller);
52 delete_aspell_config(it->second.config);
57 void ASpell::addSpeller(string const & lang)
59 AspellConfig * config = new_aspell_config();
60 aspell_config_replace(config, "language-tag", lang.c_str());
61 AspellCanHaveError * err = new_aspell_speller(config);
62 if (spell_error_object)
63 delete_aspell_can_have_error(spell_error_object);
64 spell_error_object = 0;
66 if (aspell_error_number(err) == 0) {
68 m.speller = to_aspell_speller(err);
72 spell_error_object = err;
77 enum ASpell::Result ASpell::check(WordLangTuple const & word)
81 Spellers::iterator it = spellers_.find(word.lang_code());
82 if (it == spellers_.end()) {
83 addSpeller(word.lang_code());
84 it = spellers_.find(word.lang_code());
86 if (it == spellers_.end())
90 AspellSpeller * m = it->second.speller;
92 int word_ok = aspell_speller_check(m, word.word().c_str(), -1);
93 Assert(word_ok != -1);
98 AspellWordList const * sugs =
99 aspell_speller_suggest(m, word.word().c_str(), -1);
101 els = aspell_word_list_elements(sugs);
102 if (aspell_word_list_empty(sugs))
111 void ASpell::insert(WordLangTuple const & word)
113 Spellers::iterator it = spellers_.find(word.lang_code());
114 if (it != spellers_.end())
115 aspell_speller_add_to_personal(it->second.speller, word.word().c_str(), -1);
119 void ASpell::accept(WordLangTuple const & word)
121 Spellers::iterator it = spellers_.find(word.lang_code());
122 if (it != spellers_.end())
123 aspell_speller_add_to_session(it->second.speller, word.word().c_str(), -1);
127 string const ASpell::nextMiss()
129 char const * str = 0;
132 str = aspell_string_enumeration_next(els);
139 string const ASpell::error()
141 char const * err = 0;
143 if (spell_error_object && aspell_error_number(spell_error_object) != 0) {
144 err = aspell_error_message(spell_error_object);