diff options
author | Vlad Voicu <vladvoic@gmail.com> | 2011-11-29 02:41:07 (GMT) |
---|---|---|
committer | vlad <vlad@tyrion.(none)> | 2012-10-13 13:55:44 (GMT) |
commit | 0a13558efc0ccf0e5afceb63c416d8cb401997ec (patch) | |
tree | 0fe17d78ecced7389b7f2a3d121b223bbce8dc26 /SwifTools/HunspellChecker.cpp | |
parent | 5e7be9a49cf540a68275f084e57a6efe8d7c1626 (diff) | |
download | swift-contrib-0a13558efc0ccf0e5afceb63c416d8cb401997ec.zip swift-contrib-0a13558efc0ccf0e5afceb63c416d8cb401997ec.tar.bz2 |
Added Factory for creeating SpellCheckers
Diffstat (limited to 'SwifTools/HunspellChecker.cpp')
-rw-r--r-- | SwifTools/HunspellChecker.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/SwifTools/HunspellChecker.cpp b/SwifTools/HunspellChecker.cpp new file mode 100644 index 0000000..2a36930 --- /dev/null +++ b/SwifTools/HunspellChecker.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2011 Voicu Vlad + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <SwifTools/HunspellChecker.h> + +#include <algorithm> +#include <hunspell/hunspell.hxx> +#include <boost/algorithm/string.hpp> + + +namespace Swift { + +HunspellChecker::HunspellChecker(const char* affix_path, const char* dictionary_path) { + speller_ = new Hunspell(affix_path, dictionary_path); +} + +HunspellChecker::~HunspellChecker() { + delete speller_; +} + +bool HunspellChecker::isCorrect(const std::string& word) { + return speller_->spell(word.c_str()); +} + +void HunspellChecker::getSuggestions(const std::string& word, std::vector<std::string>& list) { + char **suggestList; + int words_returned; + if (!word.empty()) { + words_returned = speller_->suggest(&suggestList, word.c_str()); + } + for (int i = 0; i < words_returned; ++i) { + list.push_back(suggestList[i]); + free(suggestList[i]); + } +} + +} |