QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
stopped = false;
+ if(word.indexOf("*")==-1)
+ word+="*";
QRegExp regWord(word);
regWord.setCaseSensitivity(Qt::CaseInsensitive);
regWord.setPatternSyntax(QRegExp::Wildcard);
- QList<Translation*> translations;
+ QSet<Translation*> translations;
QFile dictionaryFile(path);
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug()<<"Error: could not open file";
- return translations;
+ return translations.toList();
}
+
+ /*read information about dictionary*/
QXmlStreamReader dictionaryReader(&dictionaryFile);
dictionaryReader.readNextStartElement();
if(dictionaryReader.name()=="xdxf") {
dictionaryReader.readNextStartElement();
if(dictionaryReader.name()=="description")
_infoNote=dictionaryReader.readElementText();
+
+ /*search word list*/
QString a;
int i=0;
while(!dictionaryReader.atEnd() && !stopped){
dictionaryReader.readNextStartElement();
a = dictionaryReader.readElementText();
if(regWord.exactMatch(a) && i<limit) {
- translations.append(new TranslationXdxf(a,_infoNote,this));
+ translations<<(new TranslationXdxf(a,_infoNote,this));
i++;
if(i>=limit)
break;
}
stopped=false;
dictionaryFile.close();
- return translations;
+ return translations.toList();
}
QString XdxfPlugin::search(QString key) {
QFile dictionaryFile(path);
+ QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
qDebug()<<"Error: could not open file";
return "";
}
else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) {
if(match) {
- QString temp(dictionaryReader.text().toString().replace("\n",""));
- dictionaryFile.close();
- return temp;
+ QString temp(dictionaryReader.text().toString().replace("\n",""));
+ qDebug()<<temp;
+ if(temp == ""){
+ while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()){
+ dictionaryReader.readNext();
+ temp+=dictionaryReader.text().toString();
+ }
+ }
+ dictionaryFile.close();
+ resultString+=temp.replace("\n","")+"\n";
+ match=false;
}
}
}
- return "";
+ return resultString;
}
void XdxfPlugin::stop() {
{
XdxfPlugin xdxfPlugin(this);
xdxfPlugin.loadDialog();
- xdxfPlugin.searchWordList("Cain",10);
- xdxfPlugin.search("Cain");
+ xdxfPlugin.searchWordList("wino",10);
+ xdxfPlugin.search("wino");
QCOMPARE(xdxfPlugin.search("Apacz"), QString("Apachee"));
// QCOMPARE(xdxfPlugin.search("sin"), QString("grzech"));
// QCOMPARE(xdxfPlugin.search("boss"), QString(""));