2 * \file AppleSpellChecker.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "AppleSpellChecker.h"
14 #include "WordLangTuple.h"
16 #include "support/lassert.h"
17 #include "support/debug.h"
18 #include "support/docstring_list.h"
19 #include "support/AppleSpeller.h"
22 using namespace lyx::support;
26 struct AppleSpellChecker::Private
37 AppleSpellChecker::Private::Private()
39 speller = newAppleSpeller();
43 AppleSpellChecker::Private::~Private()
45 freeAppleSpeller(speller);
50 AppleSpellChecker::AppleSpellChecker(): d(new Private)
55 AppleSpellChecker::~AppleSpellChecker()
61 SpellChecker::Result AppleSpellChecker::check(WordLangTuple const & word)
63 string const word_str = to_utf8(word.word());
64 int const word_ok = checkAppleSpeller(d->speller, word_str.c_str(), word.lang()->code().c_str());
65 return (word_ok) ? OK : UNKNOWN_WORD;
69 // add to personal dictionary
70 void AppleSpellChecker::insert(WordLangTuple const & word)
72 string const word_str = to_utf8(word.word());
73 learnAppleSpeller(d->speller, word_str.c_str(), word.lang()->code().c_str());
78 void AppleSpellChecker::accept(WordLangTuple const & word)
80 string const word_str = to_utf8(word.word());
81 ignoreAppleSpeller(d->speller, word_str.c_str(), word.lang()->code().c_str());
85 void AppleSpellChecker::suggest(WordLangTuple const & wl,
86 docstring_list & suggestions)
89 string const word_str = to_utf8(wl.word());
90 size_t num = makeSuggestionAppleSpeller(d->speller, word_str.c_str(), wl.lang()->code().c_str());
91 for (size_t i = 0; i < num; i++) {
92 char const * next = getSuggestionAppleSpeller(d->speller, i);
94 suggestions.push_back(from_utf8(next));
99 bool AppleSpellChecker::hasDictionary(Language const * lang) const
101 return hasLanguageAppleSpeller(d->speller,lang->code().c_str());
105 docstring const AppleSpellChecker::error()