improve a search function in xdxfPlugin
authorJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Tue, 17 Aug 2010 12:35:43 +0000 (14:35 +0200)
committerJakub Jaszczynski <j.j.jaszczynski@gmail.com>
Tue, 17 Aug 2010 12:35:43 +0000 (14:35 +0200)
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/test.cpp

index 03b0460..ad8887c 100644 (file)
@@ -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("</");
-                            else
+                            if(dictionaryReader.tokenType()==QXmlStreamReader::StartElement)
                                 temp+=tr("<");
+                            qDebug()<<dictionaryReader.tokenType();
                             temp=temp+dictionaryReader.name().toString() + 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("</");
+                        if(dictionaryReader.tokenType()==QXmlStreamReader::StartElement)
+                            temp+=tr("<");
+                        temp=temp+dictionaryReader.name().toString() + tr(">");
+                    }
+                    temp+= dictionaryReader.text().toString();
+                    dictionaryReader.readNext();
+                }
+                resultString+=tr("<t>") + temp.replace("\n","") + tr("</t>");
+                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("</");
-                            else
-                                temp+=tr("<");
-                            temp=temp+reader.name().toString() + tr(">");
-                            i++;
-                        }
-                        temp+=reader.text().toString();
+                QString temp("");
+                while(reader.name()!="ar" && !reader.atEnd()) {
+                    if(reader.name()!="") {
+                        if(reader.tokenType()==QXmlStreamReader::EndElement)
+                            temp+=tr("</");
+                        if(reader.tokenType()==QXmlStreamReader::StartElement)
+                            temp+=tr("<");
+                        temp=temp+reader.name().toString() + tr(">");
                     }
+                    temp+= reader.text().toString();
+                    reader.readNext();
                 }
+                temp=tr("<t>") + temp.replace("\n","") + tr("</t>");
                 match = false;
                 cur.prepare("insert into dict values(?,?)");
                 cur.addBindValue(a);
index 0d37013..77b7d9d 100644 (file)
@@ -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("<t>kropka</t>"));
+    QCOMPARE(xdxfPlugin->search("1"), QString("<t>one</t>"));
 
-    QCOMPARE(xdxfPlugin->search("test"), QString("<pos>krowa</pos>test01\n"));
+    QCOMPARE(xdxfPlugin->search("test"), QString("<t><pos>krowa</pos>test01</t>"));
 }
 
 void XdxfTest::searchWordList() {