29 #include <QMutexLocker>
34 if (langCode.length()!=2)
37 return QLocale(langCode).name();
42 #include <hunspell/hunspell.hxx>
45 struct SpellerAndCodec
49 SpellerAndCodec():speller(0){}
50 SpellerAndCodec(
const QString& langCode);
53 SpellerAndCodec::SpellerAndCodec(
const QString& langCode)
56 QString dic=QString(
"/usr/share/myspell/dicts/%1.dic").arg(langCode);
57 if (!QFileInfo(dic).exists())
58 dic=QString(
"/usr/share/myspell/dicts/%1.dic").arg(
enhanceLangCode(langCode));;
59 if (QFileInfo(dic).exists())
61 speller =
new Hunspell(QString(
"/usr/share/myspell/dicts/%1.aff").arg(langCode).toUtf8().constData(),dic.toUtf8().constData());
62 codec=QTextCodec::codecForName(speller->get_dic_encoding());
64 codec=QTextCodec::codecForLocale();
68 static QMap<QString,SpellerAndCodec> hunspellers;
72 QString
stem(
const QString& langCode,
const QString& word)
78 QMutexLocker locker(&mutex);
80 if (!hunspellers.contains(langCode))
82 hunspellers.insert(langCode,SpellerAndCodec(langCode));
85 SpellerAndCodec sc(hunspellers.value(langCode));
86 Hunspell* speller=sc.speller;
92 int n1 = speller->analyze(&result1, sc.codec->fromUnicode(word));
93 int n2 = speller->stem(&result2, result1, n1);
96 result=sc.codec->toUnicode(result2[0]);
98 speller->free_list(&result1, n1);
99 speller->free_list(&result2, n2);
108 foreach(
const SpellerAndCodec& sc, hunspellers)
QString stem(const QString &langCode, const QString &word)
QString enhanceLangCode(const QString &langCode)