Skip to content

Commit

Permalink
Merge pull request #8 from Vitozz/master
Browse files Browse the repository at this point in the history
Fixed build with hunspell-1.5.3
  • Loading branch information
Ri0n committed Nov 29, 2016
2 parents dc15ca5 + 8e04a93 commit 4e4f50d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tools/spellchecker/hunspellchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "applicationinfo.h"
#endif

#ifdef H_DEPRECATED
#define NEW_HUNSPELL
#endif

HunspellChecker::HunspellChecker()
{
Expand Down Expand Up @@ -133,31 +136,49 @@ QList<QString> HunspellChecker::suggestions(const QString& word)
{
QStringList qtResult;
foreach (const LangItem &li, languages_) {
#ifdef NEW_HUNSPELL
std::vector<std::string> result = li.hunspell_->suggest(li.codec->fromUnicode(word).toStdString());
if(!result.empty()){
foreach (const std::string &item, result) {
qtResult << QString(li.codec->toUnicode(item.c_str()));
}
}
#else
char **result;
int sugNum = li.hunspell_->suggest(&result, li.codec->fromUnicode(word));
for (int i=0; i < sugNum; i++) {
qtResult << li.codec->toUnicode(result[i]);
}
li.hunspell_->free_list(&result, sugNum);
#endif
}
return qtResult;
}

bool HunspellChecker::isCorrect(const QString &word)
{
foreach (const LangItem &li, languages_) {
#ifdef NEW_HUNSPELL
if (li.hunspell_->spell(li.codec->fromUnicode(word).toStdString()) != 0) {
#else
if (li.hunspell_->spell(li.codec->fromUnicode(word)) != 0) {
#endif
return true;
}
}

return false;
}
bool HunspellChecker::add(const QString& word)
{
if (!word.isEmpty()) {
QString trimmed_word = word.trimmed();
foreach (const LangItem &li, languages_) {
#ifdef NEW_HUNSPELL
if (li.hunspell_->add(li.codec->fromUnicode(trimmed_word).toStdString()) != 0) {
#else
if (li.hunspell_->add(li.codec->fromUnicode(trimmed_word)) != 0) {
#endif
return true;
}
}
Expand Down

0 comments on commit 4e4f50d

Please sign in to comment.