2 * \file HunspellChecker.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Abdelrazak Younes
8 * Full author contact details are available in file CREDITS.
13 #include "HunspellChecker.h"
16 #include "WordLangTuple.h"
18 #include "support/lassert.h"
19 #include "support/debug.h"
20 #include "support/docstring_list.h"
22 #include <hunspell/hunspell.hxx>
27 // FIXME (Abdel): I still got linking problems but if anybody wants
28 // to try, defines this to 1.
29 #define TRY_HUNSPELL 0
37 typedef map<std::string, Hunspell *> Spellers;
41 struct HunspellChecker::Private
47 Hunspell * addSpeller(string const & lang);
48 Hunspell * speller(string const & lang);
55 HunspellChecker::Private::~Private()
58 Spellers::iterator it = spellers_.begin();
59 Spellers::iterator end = spellers_.end();
61 for (; it != end; ++it) {
68 Hunspell * HunspellChecker::Private::addSpeller(string const & lang)
70 // FIXME: not implemented!
72 // FIXME: We should we indicate somehow that this language is not
78 Hunspell * HunspellChecker::Private::speller(string const & lang)
80 Spellers::iterator it = spellers_.find(lang);
81 if (it != spellers_.end())
84 return addSpeller(lang);
88 HunspellChecker::HunspellChecker(): d(new Private)
93 HunspellChecker::~HunspellChecker()
99 SpellChecker::Result HunspellChecker::check(WordLangTuple const & wl)
101 string const word_to_check = to_utf8(wl.word());
103 Hunspell * h = d->speller(wl.lang_code());
105 if (h->spell(word_to_check.c_str(), &info))
107 // FIXME: What to do with that?
110 case SPELL_FORBIDDEN:
120 void HunspellChecker::insert(WordLangTuple const & wl)
122 string const word_to_check = to_utf8(wl.word());
124 Hunspell * h = d->speller(wl.lang_code());
125 h->add(word_to_check.c_str());
130 void HunspellChecker::accept(WordLangTuple const & word)
132 // FIXME: not implemented!
136 void HunspellChecker::suggest(WordLangTuple const & wl,
137 docstring_list & suggestions)
140 string const word_to_check = to_utf8(wl.word());
142 Hunspell * h = d->speller(wl.lang_code());
143 char *** suggestion_list = 0;
144 int const suggestion_number = h->suggest(suggestion_list, word_to_check.c_str());
145 if (suggestion_number == 0)
147 h->free_list(suggestion_list, suggestion_number);
152 docstring const HunspellChecker::error()