From 4509ff7578f3348b5a712dc2b63bcc2fd847667c Mon Sep 17 00:00:00 2001 From: Jakub Jaszczynski Date: Tue, 17 Aug 2010 14:35:43 +0200 Subject: [PATCH] improve a search function in xdxfPlugin --- trunk/src/plugins/xdxf/src/xdxfplugin.cpp | 52 ++++++++++++++++++----------- trunk/src/plugins/xdxf/tests/test.cpp | 6 ++-- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp index 03b0460..ad8887c 100644 --- a/trunk/src/plugins/xdxf/src/xdxfplugin.cpp +++ b/trunk/src/plugins/xdxf/src/xdxfplugin.cpp @@ -212,7 +212,7 @@ QString XdxfPlugin::searchFile(QString key) { } else if(dictionaryReader.tokenType() == QXmlStreamReader::Characters) { if(match) { - QString temp(dictionaryReader.text().toString()); + /* QString temp(dictionaryReader.text().toString()); if(temp=="\n") temp=dictionaryReader.readElementText(); temp.replace("\n",""); @@ -221,11 +221,13 @@ QString XdxfPlugin::searchFile(QString key) { while(dictionaryReader.name()!="ar"&& !dictionaryReader.atEnd()){ dictionaryReader.readNext(); - if(dictionaryReader.name()!="" && dictionaryReader.name()!="ar") { - if(i%2) + if(dictionaryReader.name()!="" && + dictionaryReader.name()!="ar") { + if(dictionaryReader.tokenType()==QXmlStreamReader::EndElement) temp+=tr(""); i++; } @@ -234,6 +236,21 @@ QString XdxfPlugin::searchFile(QString key) { } resultString+=temp.replace("\n","")+"\n"; match=false; +*/ + QString temp(""); + while(dictionaryReader.name()!="ar" && !dictionaryReader.atEnd()) { + if(dictionaryReader.name()!="") { + if(dictionaryReader.tokenType()==QXmlStreamReader::EndElement) + temp+=tr(""); + } + temp+= dictionaryReader.text().toString(); + dictionaryReader.readNext(); + } + resultString+=tr("") + temp.replace("\n","") + tr(""); + match=false; } } this->thread()->yieldCurrentThread(); @@ -460,24 +477,19 @@ bool XdxfPlugin::makeCache(QString dir) { } else if(reader.tokenType() == QXmlStreamReader::Characters) { if(match) { - QString temp(reader.text().toString()); - temp.replace("\n",""); - if(temp == ""){ - int i=0; - while(reader.name()!="ar"&& - !reader.atEnd()){ - reader.readNext(); - if(reader.name()!="" && reader.name()!="ar") { - if(i%2) - temp+=tr(""); - i++; - } - temp+=reader.text().toString(); + QString temp(""); + while(reader.name()!="ar" && !reader.atEnd()) { + if(reader.name()!="") { + if(reader.tokenType()==QXmlStreamReader::EndElement) + temp+=tr(""); } + temp+= reader.text().toString(); + reader.readNext(); } + temp=tr("") + temp.replace("\n","") + tr(""); match = false; cur.prepare("insert into dict values(?,?)"); cur.addBindValue(a); diff --git a/trunk/src/plugins/xdxf/tests/test.cpp b/trunk/src/plugins/xdxf/tests/test.cpp index 0d37013..77b7d9d 100644 --- a/trunk/src/plugins/xdxf/tests/test.cpp +++ b/trunk/src/plugins/xdxf/tests/test.cpp @@ -43,10 +43,10 @@ void XdxfTest::search() { CommonDictInterface *xdxfPlugin = xdxfPluginB.getNew(settings); xdxfPlugin->search("wino"); - QCOMPARE(xdxfPlugin->search("."), QString("kropka\n")); - QCOMPARE(xdxfPlugin->search("1"), QString("one\n")); + QCOMPARE(xdxfPlugin->search("."), QString("kropka")); + QCOMPARE(xdxfPlugin->search("1"), QString("one")); - QCOMPARE(xdxfPlugin->search("test"), QString("krowatest01\n")); + QCOMPARE(xdxfPlugin->search("test"), QString("krowatest01")); } void XdxfTest::searchWordList() { -- 1.7.9.5