[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kutils
From:       David Faure <faure () kde ! org>
Date:       2005-03-31 13:13:04
Message-ID: 20050331131304.870454A6 () office ! kde ! org
[Download RAW message or body]

CVS commit by faure: 

QDict doesn't like the empty string as key, it gives a warning about it.
Changed to use a separate member for the data associated with the empty string.
CCMAIL: Arend van Beelen jr. <arend@auton.nl>


  M +17 -3     kfind.cpp   1.26
  M +24 -7     tests/kfindtest.cpp   1.4


--- kdelibs/kutils/kfind.cpp  #1.25:1.26
@@ -63,4 +63,5 @@ struct KFind::Private
       matchedPattern(""),
       incrementalPath(29, true),
+      emptyMatch(0),
       currentId(0),
       customIds(false)
@@ -70,4 +71,10 @@ struct KFind::Private
     }
 
+    ~Private()
+    {
+        delete emptyMatch;
+        emptyMatch = 0;
+    }
+
     struct Match
     {
@@ -101,4 +108,5 @@ struct KFind::Private
     QString               matchedPattern;
     QDict<Match>          incrementalPath;
+    Match *               emptyMatch;
     QPtrVector<Data>      data;
     int                   currentId;
@@ -237,5 +245,5 @@ KFind::Result KFind::find()
         if ( m_pattern.length() < d->matchedPattern.length() )
         {
-            Private::Match *match = d->incrementalPath[m_pattern];
+            Private::Match *match = m_pattern.isEmpty() ? d->emptyMatch : \
d->incrementalPath[m_pattern];  QString previousPattern = d->matchedPattern;
             d->matchedPattern = m_pattern;
@@ -358,4 +366,8 @@ KFind::Result KFind::find()
                 if ( m_options & KFindDialog::FindIncremental )
                 {
+                    if ( m_pattern.isEmpty() ) {
+                        delete d->emptyMatch;
+                        d->emptyMatch = new Private::Match( d->currentId, m_index, \
m_matchedLength ); +                    } else
                     d->incrementalPath.replace(m_pattern, new \
Private::Match(d->currentId, m_index, m_matchedLength));  
@@ -419,5 +431,5 @@ KFind::Result KFind::find()
 void KFind::startNewIncrementalSearch()
 {
-    Private::Match *match = d->incrementalPath[""];
+    Private::Match *match = d->emptyMatch;
     if(match == 0)
     {
@@ -434,4 +446,6 @@ void KFind::startNewIncrementalSearch()
     m_matchedLength = 0;
     d->incrementalPath.clear();
+    delete d->emptyMatch;
+    d->emptyMatch = 0;
     d->matchedPattern = m_pattern;
     m_pattern = QString::null;

--- kdelibs/kutils/tests/kfindtest.cpp  #1.3:1.4
@@ -18,5 +18,7 @@
 */
 
-#include <assert.h>
+#include "../kfind.h"
+#include "../kfinddialog.h"
+#include "kfindtest.h"
 
 #include <kapplication.h>
@@ -24,7 +26,22 @@
 #include <kdebug.h>
 
-#include "kfindtest.h"
-#include "../kfind.h"
-#include "../kfinddialog.h"
+#include <stdlib.h>
+#include <assert.h>
+
+static bool check(QString txt, QString a, QString b) // from kurltest
+{
+  if (a.isEmpty())
+     a = QString::null;
+  if (b.isEmpty())
+     b = QString::null;
+  if (a == b) {
+    kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << \
"'... " << "ok" << endl; +  }
+  else {
+    kdDebug() << txt << " : checking '" << a << "' against expected value '" << b << \
"'... " << "KO !" << endl; +    exit(1);
+  }
+  return true;
+}
 
 void KFindTest::changeText(uint line, const QString &text)
@@ -175,5 +192,5 @@ int main(int argc, char **argv)
         test->findNext();
 
-        assert(test->hits().join("") == output1);
+        check("result", test->hits().join(""), output1);
         test->clearHits();
         kdDebug() << "PASSED" << endl;
@@ -197,5 +214,5 @@ int main(int argc, char **argv)
         test->findNext("Software Foundation");
 
-        assert(test->hits().join("") == output2);
+        check("result", test->hits().join(""), output2);
         test->clearHits();
         kdDebug() << "PASSED" << endl;
@@ -224,5 +241,5 @@ int main(int argc, char **argv)
         test->findNext("Software Foundation");
 
-        assert(test->hits().join("") == output3);
+        check("result", test->hits().join(""), output3);
         test->clearHits();
         kdDebug() << "PASSED" << endl;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic