3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
6 * \author Kevin Atkinson
7 * \author John Levon <levon@movementarian.org>
14 #include "support/LAssert.h"
19 #include "aspell_local.h"
20 #include "WordLangTuple.h"
24 ASpell::ASpell(BufferParams const &, string const & lang)
25 : els(0), spell_error_object(0)
33 if (spell_error_object) {
34 delete_aspell_can_have_error(spell_error_object);
35 spell_error_object = 0;
39 delete_aspell_string_enumeration(els);
41 Spellers::iterator it = spellers_.begin();
42 Spellers::iterator end = spellers_.end();
44 for (; it != end; ++it) {
45 aspell_speller_save_all_word_lists(it->second.speller);
46 delete_aspell_speller(it->second.speller);
47 delete_aspell_config(it->second.config);
52 void ASpell::addSpeller(string const & lang)
54 AspellConfig * config = new_aspell_config();
55 aspell_config_replace(config, "language-tag", lang.c_str());
56 AspellCanHaveError * err = new_aspell_speller(config);
57 if (spell_error_object)
58 delete_aspell_can_have_error(spell_error_object);
59 spell_error_object = 0;
61 if (aspell_error_number(err) == 0) {
63 m.speller = to_aspell_speller(err);
67 spell_error_object = err;
72 enum ASpell::Result ASpell::check(WordLangTuple const & word)
76 Spellers::iterator it = spellers_.find(word.lang_code());
77 if (it == spellers_.end()) {
78 addSpeller(word.lang_code());
79 it = spellers_.find(word.lang_code());
81 if (it == spellers_.end())
85 AspellSpeller * m = it->second.speller;
87 int word_ok = aspell_speller_check(m, word.word().c_str(), -1);
88 lyx::Assert(word_ok != -1);
93 AspellWordList const * sugs =
94 aspell_speller_suggest(m, word.word().c_str(), -1);
95 lyx::Assert(sugs != 0);
96 els = aspell_word_list_elements(sugs);
97 if (aspell_word_list_empty(sugs))
106 void ASpell::insert(WordLangTuple const & word)
108 Spellers::iterator it = spellers_.find(word.lang_code());
109 if (it != spellers_.end())
110 aspell_speller_add_to_personal(it->second.speller, word.word().c_str(), -1);
114 void ASpell::accept(WordLangTuple const & word)
116 Spellers::iterator it = spellers_.find(word.lang_code());
117 if (it != spellers_.end())
118 aspell_speller_add_to_session(it->second.speller, word.word().c_str(), -1);
122 string const ASpell::nextMiss()
124 char const * str = 0;
127 str = aspell_string_enumeration_next(els);
134 string const ASpell::error()
136 char const * err = 0;
138 if (spell_error_object && aspell_error_number(spell_error_object) != 0) {
139 err = aspell_error_message(spell_error_object);