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

List:       kde-commits
Subject:    KDE/kdelibs/kdecore
From:       Anne-Marie Mahfouf <annma () kde ! org>
Date:       2010-12-13 19:55:13
Message-ID: 20101213195513.2099FAC8A7 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1206184 by annma:

fix wrong separation of French words with single quote
add general unit tests for preProcessWrap, thanks to Fredrikh 
BUG=257988


 M  +94 -0     tests/kstringhandlertest.cpp  
 M  +2 -0      tests/kstringhandlertest.h  
 M  +6 -1      text/kstringhandler.cpp  


--- trunk/KDE/kdelibs/kdecore/tests/kstringhandlertest.cpp #1206183:1206184
@@ -155,3 +155,97 @@
   QCOMPARE( KStringHandler::obscure( QString::fromUtf8( obscuredBytes ) ), test );
 }
 
+void KStringHandlerTest::preProcessWrap_data()
+{
+    const QChar zwsp(0x200b);
+
+    QTest::addColumn<QString>("string");
+    QTest::addColumn<QString>("expected");
+
+    // Should result in no additional breaks
+    QTest::newRow("spaces") << "foo bar baz" << "foo bar baz";
+
+    // Should insert a ZWSP after each '_' 
+    QTest::newRow("underscores") << "foo_bar_baz"
+               << QString("foo_") + zwsp + "bar_" + zwsp + "baz";
+
+    // Should insert a ZWSP after each '-' 
+    QTest::newRow("hyphens") << "foo-bar-baz"
+                << QString("foo-") + zwsp + "bar-" + zwsp + "baz";
+
+    // Should insert a ZWSP after each '.' 
+    QTest::newRow("periods") << "foo.bar.baz"
+                << QString("foo.") + zwsp + "bar." + zwsp + "baz";
+
+    // Should insert a ZWSP after each ',' 
+    QTest::newRow("commas") << "foo,bar,baz"
+                << QString("foo,") + zwsp + "bar," + zwsp + "baz";
+
+    // Should result in no additional breaks since the '_'s are followed by spaces 
+    QTest::newRow("mixed underscores and spaces")
+                << "foo_ bar_ baz" << "foo_ bar_ baz";
+
+    // Should result in no additional breaks since the '_' is the last char 
+    QTest::newRow("ends with underscore") << "foo_" << "foo_";
+
+    // Should insert a ZWSP before '(' and after ')' 
+    QTest::newRow("parens") << "foo(bar)baz" 
+                << QString("foo") + zwsp + "(bar)" + zwsp + "baz";
+
+    // Should insert a ZWSP before '[' and after ']' 
+    QTest::newRow("brackets") << "foo[bar]baz" 
+                << QString("foo") + zwsp + "[bar]" + zwsp + "baz";
+
+    // Should insert a ZWSP before '{' and after '}' 
+    QTest::newRow("curly braces") << "foo{bar}baz" 
+                << QString("foo") + zwsp + "{bar}" + zwsp + "baz";
+
+    // Should insert a ZWSP before '(' but not after ')' since it's the last char 
+    QTest::newRow("ends with ')'") << "foo(bar)" 
+                << QString("foo") + zwsp + "(bar)";
+
+    // Should insert a single ZWSP between the '_' and the '(' 
+    QTest::newRow("'_' followed by '('") << "foo_(bar)" 
+                << QString("foo_") + zwsp + "(bar)";
+
+    // Should insert ZWSP's between the '_' and the '[', between the double
+    // '['s and the double ']'s, but not before and after 'bar' 
+    QTest::newRow("'_' before double brackets") << "foo_[[bar]]" 
+                << QString("foo_") + zwsp + "[" + zwsp + "[bar]" + zwsp + "]";
+
+    // Should only insert ZWSP's between the double '['s and the double ']'s 
+    QTest::newRow("space before double brackets") << "foo [[bar]]" 
+                << QString("foo [") + zwsp + "[bar]" + zwsp + "]";
+
+    // Shouldn't result in any additional breaks since the '(' is preceeded
+    // by a space, and the ')' is followed by a space.
+    QTest::newRow("parens with spaces") << "foo (bar) baz" << "foo (bar) baz";
+    
+    // Should insert a WJ (Word Joiner) before a single quote 
+    const QChar wj(0x2060);
+    QTest::newRow("single quote") << "foo'bar"<< QString("foo")+ wj +"'bar" ; 
+}
+
+static QString replaceZwsp(const QString &string)
+{
+    const QChar zwsp(0x200b);
+
+    QString result;
+    for (int i = 0; i < string.length(); i++)
+        if (string[i] == zwsp)
+            result += "<zwsp>";
+        else
+            result += string[i];
+
+    return result;
+}
+
+void KStringHandlerTest::preProcessWrap()
+{
+    QFETCH(QString, string);
+    QFETCH(QString, expected);
+
+    QCOMPARE(replaceZwsp(KStringHandler::preProcessWrap(string)),
+             replaceZwsp(expected));
+}
+
--- trunk/KDE/kdelibs/kdecore/tests/kstringhandlertest.h #1206183:1206184
@@ -13,6 +13,8 @@
     void perlSplit();
     void naturalCompare();
     void obscure();
+    void preProcessWrap_data();
+    void preProcessWrap();
 
 private:
     static QString test;
--- trunk/KDE/kdelibs/kdecore/text/kstringhandler.cpp #1206183:1206184
@@ -460,6 +460,7 @@
     for (int i = 0; i < text.length(); i++) {
         const QChar c = text[i];
         bool openingParens = (c == QLatin1Char('(') || c == QLatin1Char('{') || c == QLatin1Char('['));
+        bool singleQuote = (c == QLatin1Char('\'') );
         bool closingParens = (c == QLatin1Char(')') || c == QLatin1Char('}') || c == QLatin1Char(']'));
         bool breakAfter   = (closingParens || c.isPunct() || c.isSymbol());
         bool nextIsSpace  = (i == (text.length() - 1) || text[i + 1].isSpace());
@@ -469,9 +470,13 @@
         if (openingParens && !prevIsSpace)
             result += zwsp;
 
+        // Provide a word joiner before the single quote
+        if (singleQuote && !prevIsSpace)
+            result += QChar(0x2060);
+
         result += c;
 
-        if (breakAfter && !openingParens && !nextIsSpace)
+        if (breakAfter && !openingParens && !nextIsSpace && !singleQuote) 
             result += zwsp;
     }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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