summaryrefslogtreecommitdiffstats
path: root/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
diff options
context:
space:
mode:
authorcraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-05-04 14:26:58 +0000
committercraig <craig@11d20701-8431-0410-a711-e3c959e3b870>2012-05-04 14:26:58 +0000
commit1601800e7d74c192af89ee85c6110bd80a02453a (patch)
treee0c473e40bac26e8e56ce3d5a8e0b5c1dfda623d /scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
parent551faae07c1a1dc272fd61a93ebffb901e382a07 (diff)
downloadscribus-1601800e7d74c192af89ee85c6110bd80a02453a.tar.gz
scribus-1601800e7d74c192af89ee85c6110bd80a02453a.tar.xz
scribus-1601800e7d74c192af89ee85c6110bd80a02453a.zip
Bump hunspell plugin, simplify a little. Allow the LibreOffice dict finder use the dict dirs properly
git-svn-id: svn://scribus.net/branches/Version14x/Scribus@17494 11d20701-8431-0410-a711-e3c959e3b870
Diffstat (limited to 'scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp')
-rw-r--r--scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp54
1 files changed, 16 insertions, 38 deletions
diff --git a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
index cbbd675..18d1a47 100644
--- a/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
+++ b/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
@@ -95,17 +95,14 @@ bool HunspellPluginImpl::initHunspell()
{
// Find the dic and aff files in the location
QDir dictLocation(dictionaryPaths.at(i));
- QStringList dictFilters;
- dictFilters << "*.dic";
+ QStringList dictFilters("*.dic");
QStringList dictList(dictLocation.entryList(dictFilters, QDir::Files, QDir::Name));
dictList.replaceInStrings(".dic","");
//Ensure we have aff+dic file pairs, remove any hyphenation dictionaries from the list
QString dictName;
- QStringListIterator dictListIterator(dictList);
- while (dictListIterator.hasNext())
+ foreach(dictName, dictList)
{
- dictName=dictListIterator.next();
if (!QFile::exists(dictionaryPaths.at(i)+dictName+".aff"))
dictList.removeAll(dictName);
else
@@ -127,7 +124,6 @@ bool HunspellPluginImpl::initHunspell()
QMap<QString, QString>::iterator it = dictionaryMap.begin();
while (it != dictionaryMap.end())
{
- qDebug() << it.key()<< it.value();
hspellers[i++] = new Hunspell((it.value()+".aff").toLocal8Bit().constData(),
(it.value()+".dic").toLocal8Bit().constData());
++it;
@@ -162,26 +158,17 @@ bool HunspellPluginImpl::checkWithHunspellSE()
bool HunspellPluginImpl::parseTextFrame(StoryText *iText)
{
int len=iText->length();
- int wordCount=0,wordNo=0,errorCount=0;
- int currPos=0, wordPos=0;
+ int currPos=0, wordStart=0;
while (currPos<len)
{
- wordPos=iText->nextWord(currPos);
- currPos=wordPos;
- int eoWord=wordPos;
- while(eoWord < len)
- {
- if (iText->text(eoWord).isLetter())
- {
- ++eoWord;
- }
- else
- break;
- }
- QString word=iText->text(wordPos,eoWord-wordPos);
- QString wordLang=iText->charStyle(wordPos).language();
+ wordStart=iText->nextWord(currPos);
+ int wordEnd=iText->endOfWord(wordStart);
+ currPos=wordStart;
+ QString word=iText->text(wordStart,wordEnd-wordStart);
+ QString wordLang=iText->charStyle(wordStart).language();
//qDebug()<<word<<"is set to be in language"<<wordLang;
wordLang=LanguageManager::instance()->getAbbrevFromLang(wordLang, true);
+ //A little hack as for some reason our en dictionary from the aspell plugin was not called en_GB or en_US but en, content was en_GB though. Meh.
if (wordLang=="en")
wordLang="en_GB";
int spellerIndex=0;
@@ -200,31 +187,22 @@ bool HunspellPluginImpl::parseTextFrame(StoryText *iText)
}
spellerIndex=i;
}
- ++wordCount;
- ++wordNo;
- QStringList replacements;
if (hspellers[spellerIndex]->spell(word.toUtf8().constData())==0)
{
-// qDebug()<<word<<wordLang;
- ++errorCount;
- char **sugglist = NULL;
- int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData());
- for (int j=0; j < suggCount; ++j)
- {
-// qDebug()<<"Suggestion "<<j<<":"<<sugglist[j];
- replacements << QString::fromUtf8(sugglist[j]);
- }
- hspellers[spellerIndex]->free_list(&sugglist, suggCount);
-
struct WordsFound wf;
wf.start=currPos;
- wf.end=eoWord;
+ wf.end=wordEnd;
wf.w=word;
- wf.replacements=replacements;
wf.changed=false;
wf.ignore=false;
wf.changeOffset=0;
wf.lang=wordLang;
+ wf.replacements.clear();
+ char **sugglist = NULL;
+ int suggCount=hspellers[spellerIndex]->suggest(&sugglist, word.toUtf8().constData());
+ for (int j=0; j < suggCount; ++j)
+ wf.replacements << QString::fromUtf8(sugglist[j]);
+ hspellers[spellerIndex]->free_list(&sugglist, suggCount);
wordsToCorrect.append(wf);
}
}