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

List:       kde-commits
Subject:    branches/kdepim/enterprise4/kdepimlibs
From:       Thomas McGuire <mcguire () kde ! org>
Date:       2009-08-26 16:13:23
Message-ID: 1251303203.854582.30019.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1015925 by tmcguire:

Merged revisions 1013328-1013329,1013331 via svnmerge from 
svn+ssh://tmcguire@svn.kde.org/home/kde/branches/KDE/4.3/kdepimlibs

........
  r1013328 | tmcguire | 2009-08-19 17:25:59 +0200 (Wed, 19 Aug 2009) | 11 lines
  
  Backport r1012151 by tmcguire from trunk to the 4.3 branch:
  
  Don't remove my whitespace if I set the PreserceSpaces flag.
  Strange is that the code seems to do that intentionally, but it is so old that svn \
annotate doesn't say anything useful.  
  
  Add small unit test for that.
  
  BUG :204101
........
  r1013329 | tmcguire | 2009-08-19 17:26:48 +0200 (Wed, 19 Aug 2009) | 7 lines
  
  Backport r1012907 by tmcguire from trunk to the 4.3 branch:
  
  Now I know why the code didn't simply replace all spaces with nbsps: That would \
break  word-wrapping.
  Therefore, take this into account and adjust the tests for it.
........
  r1013331 | tmcguire | 2009-08-19 17:27:44 +0200 (Wed, 19 Aug 2009) | 7 lines
  
  Backport r1012912 by tmcguire from trunk to the 4.3 branch:
  
  Fix spaces one and for all, hopefully.
  I forgot that in a sequence of spaces, all must be non-breaking, otherwise the \
breaking one  isn't taken into account.
........


 _M            . (directory)  
 M  +29 -11    kpimutils/linklocator.cpp  
 M  +37 -3     kpimutils/tests/testlinklocator.cpp  
 M  +2 -0      kpimutils/tests/testlinklocator.h  


** branches/kdepim/enterprise4/kdepimlibs #property svnmerge-integrated
   - /branches/KDE/4.3/kdepimlibs:1-986158,990023,990532,990575,990631,990684,991932,996755,997101,997490,998251,1000615,1007460,1008037,1008812,1009437,1011841
  + /branches/KDE/4.3/kdepimlibs:1-986158,990023,990532,990575,990631,990684,991932,99 \
6755,997101,997490,998251,1000615,1007460,1008037,1008812,1009437,1011841,1013328-1013331
                
--- branches/kdepim/enterprise4/kdepimlibs/kpimutils/linklocator.cpp #1015924:1015925
@@ -272,20 +272,38 @@
     ch = locator.mText[locator.mPos];
     if ( flags & PreserveSpaces ) {
       if ( ch == ' ' ) {
+        if ( locator.mPos + 1 < locator.mText.length() ) {
+          if ( locator.mText[locator.mPos + 1] != ' ' ) {
+
+            // A single space, make it breaking if not at the start or end of the \
line +            const bool endOfLine = locator.mText[locator.mPos + 1] == '\n';
+            if ( !startOfLine && !endOfLine )
+              result += ' ';
+            else
+              result += "&nbsp;";
+          }
+          else {
+
+            // Whitespace of more than one space, make it all non-breaking
+            while( locator.mPos < locator.mText.length() && \
locator.mText[locator.mPos] == ' ' ) { +              result += "&nbsp;";
+              locator.mPos++;
+              x++;
+            }
+
+            // We incremented once to often, undo that
+            locator.mPos--;
+            x--;
+          }
+        }
+        else {
+          // Last space in the text, it is non-breaking
+          result += "&nbsp;";
+        }
+
         if ( startOfLine ) {
-          result += "&nbsp;";
-          locator.mPos++, x++;
           startOfLine = false;
         }
-        while ( locator.mText[locator.mPos] == ' ' ) {
-          result += ' ';
-          locator.mPos++, x++;
-          if ( locator.mText[locator.mPos] == ' ' ) {
-            result += "&nbsp;";
-            locator.mPos++, x++;
-          }
-        }
-        locator.mPos--, x--;
         continue;
       } else if ( ch == '\t' ) {
         do
--- branches/kdepim/enterprise4/kdepimlibs/kpimutils/tests/testlinklocator.cpp \
#1015924:1015925 @@ -151,7 +151,7 @@
       QString gotUrl = ll.getUrl();
 
       bool ok = ( gotUrl == (schema + url) );
-      qDebug() << "check:" << (ok ? "OK" : "NOK") << test << "=>" << (schema + url);
+      //qDebug() << "check:" << (ok ? "OK" : "NOK") << test << "=>" << (schema + \
url);  QVERIFY2( ok, qPrintable(test) );
     }
   }
@@ -176,7 +176,7 @@
       QString gotUrl = ll.getUrl();
 
       bool ok = ( gotUrl == (start + url) );
-      qDebug() << "check:" << (ok ? "OK" : "NOK") << test << "=>" << (start + url);
+      //qDebug() << "check:" << (ok ? "OK" : "NOK") << test << "=>" << (start + \
url);  QVERIFY2( ok, qPrintable(test) );
     }
   }
@@ -190,7 +190,41 @@
     QString gotUrl = ll.getUrl();
 
     bool ok = ( gotUrl == addr );
-    qDebug() << "check:" << (ok ? "OK" : "NOK") << test << "=>" << addr;
+    //qDebug() << "check:" << (ok ? "OK" : "NOK") << test << "=>" << addr;
     QVERIFY2( ok, qPrintable(test) );
   }
 }
+
+void LinkLocatorTest::testHtmlConvert_data()
+{
+  QTest::addColumn<QString>("plainText");
+  QTest::addColumn<int>("flags");
+  QTest::addColumn<QString>("htmlText");
+
+  //QTest::newRow( "" ) << "foo" << 0 << "foo";
+  //QTest::newRow( "" ) << "  foo " << 0 << "  foo ";
+  // Linker error when using PreserveSpaces, therefore the hardcoded 0x01
+  QTest::newRow( "" ) << " foo" << 0x01 << "&nbsp;foo";
+  QTest::newRow( "" ) << "  foo" << 0x01 << "&nbsp;&nbsp;foo";
+  QTest::newRow( "" ) << "  foo  " << 0x01 << "&nbsp;&nbsp;foo&nbsp;&nbsp;";
+  QTest::newRow( "" ) << "  foo " << 0x01 << "&nbsp;&nbsp;foo&nbsp;";
+  QTest::newRow( "" ) << "bla bla bla bla bla" << 0x01 << "bla bla bla bla bla";
+  QTest::newRow( "" ) << "bla bla bla \n  bla bla bla " << 0x01
+                      << "bla bla bla&nbsp;<br />\n&nbsp;&nbsp;bla bla bla&nbsp;";
+  QTest::newRow( "" ) << "bla bla  bla" << 0x01
+                      << "bla bla&nbsp;&nbsp;bla";
+  QTest::newRow( "" ) << " bla bla \n bla bla a\n  bla bla " << 0x01
+                      << "&nbsp;bla bla&nbsp;<br />\n&nbsp;bla bla a<br \
/>\n&nbsp;&nbsp;bla bla&nbsp;"; +}
+
+void LinkLocatorTest::testHtmlConvert()
+{
+  QFETCH(QString, plainText);
+  QFETCH(int, flags);
+  QFETCH(QString, htmlText);
+
+  QString actualHtml = LinkLocator::convertToHtml( plainText, flags );
+  QCOMPARE( actualHtml, htmlText );
+}
+
+
--- branches/kdepim/enterprise4/kdepimlibs/kpimutils/tests/testlinklocator.h \
#1015924:1015925 @@ -30,6 +30,8 @@
   private Q_SLOTS:
     void testGetEmailAddress();
     void testGetUrl();
+    void testHtmlConvert();
+    void testHtmlConvert_data();
 
   private:
     void testGetUrl2(const QString &left, const QString &right);


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

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