Added tests for removeAccents(), updated array of accents, removed unnecessary reimpl...
authorPiotrek <ppilar11@gmail.com>
Fri, 27 Aug 2010 10:55:10 +0000 (12:55 +0200)
committerPiotrek <ppilar11@gmail.com>
Fri, 27 Aug 2010 10:55:10 +0000 (12:55 +0200)
trunk/src/includes/AccentsNormalizer.h
trunk/src/includes/CommonDictInterface.h
trunk/src/plugins/xdxf/src/xdxfplugin.cpp
trunk/src/plugins/xdxf/tests/test.cpp
trunk/src/plugins/xdxf/tests/test.h

index d94a6b2..dc378c6 100644 (file)
@@ -49,27 +49,32 @@ class AccentsNormalizer {
        return normalized;
     }
     void initAccents() {
-        letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹]"), Qt::CaseInsensitive);
-        letters['c'] = QRegExp(QString::fromUtf8("[ÇçÈçŒĆćĈĉĊċČč]"), Qt::CaseInsensitive);
-        letters['d'] = QRegExp(QString::fromUtf8("[ÐĐđĎď]"), Qt::CaseInsensitive);
-        letters['e'] = QRegExp(QString::fromUtf8("[ÈéèÉÊêËëĒēĔĕĖėĘęĚěē]"), Qt::CaseInsensitive);
-        letters['f'] = QRegExp(QString::fromUtf8("[ſ]"), Qt::CaseInsensitive);
-        letters['g'] = QRegExp(QString::fromUtf8("[ĠġĢģĜĝĞğ]"), Qt::CaseInsensitive);
-        letters['h'] = QRegExp(QString::fromUtf8("[ħĤĥĦ]"), Qt::CaseInsensitive);
-        letters['i'] = QRegExp(QString::fromUtf8("[ÌìÍíÎîÏïİijĨĩĪīĬĭĮį]"), Qt::CaseInsensitive);
-        letters['j'] = QRegExp(QString::fromUtf8("[Ĵĵ]"), Qt::CaseInsensitive);
-        letters['k'] = QRegExp(QString::fromUtf8("[Ķķĸ]"), Qt::CaseInsensitive);
-        letters['l'] = QRegExp(QString::fromUtf8("[ŀŁłĹĺĻļĽľĿ]"), Qt::CaseInsensitive);
-        letters['n'] = QRegExp(QString::fromUtf8("[ÑñŃńŅņŇňʼnŊŋ]"), Qt::CaseInsensitive);
-        letters['o'] = QRegExp(QString::fromUtf8("[ÒòÓóÔÕõÖöØøŐőœŌōŎŏ]"), Qt::CaseInsensitive);
-        letters['r'] = QRegExp(QString::fromUtf8("[ŕŖŖŗŘř]"), Qt::CaseInsensitive);
-        letters['s'] = QRegExp(QString::fromUtf8("[ߊšŚśŜŝŞş]"), Qt::CaseInsensitive);
-        letters['t'] = QRegExp(QString::fromUtf8("[ŢţŤťŦŧ]"), Qt::CaseInsensitive);
-        letters['u'] = QRegExp(QString::fromUtf8("[ÙùÚúÛûÜüŰűŲųŨũŪūŬŮů]"), Qt::CaseInsensitive);
-        letters['w'] = QRegExp(QString::fromUtf8("[Ŵŵ]"), Qt::CaseInsensitive);
-        letters['y'] = QRegExp(QString::fromUtf8("[ÿÝýŶŷŸ]"), Qt::CaseInsensitive);
-        letters['z'] = QRegExp(QString::fromUtf8("[ŹźŻżŽž]"), Qt::CaseInsensitive);
-        noLetter = QRegExp("[^a-z ]", Qt::CaseInsensitive);
+        letters['a'] = QRegExp(QString::fromUtf8("[ÀàÁáÂÂâÃãÄäÅåæÆĀāĂ㥹ǠȀǡȁǢȂǣȃȦȧǺȺǻǼǍǽǎǞǟⱥ]"), Qt::CaseInsensitive);
+        letters['b'] = QRegExp(QString::fromUtf8("[ƀƁƂƃɃƄƅ]"), Qt::CaseInsensitive);
+        letters['c'] = QRegExp(QString::fromUtf8("[ÇçÈçŒĆćĈĉĊċČčƇƈȻȼ]"), Qt::CaseInsensitive);
+        letters['d'] = QRegExp(QString::fromUtf8("[ÐĐđĎďȡƉ]"), Qt::CaseInsensitive);
+        letters['e'] = QRegExp(QString::fromUtf8("[ÈéèÉÊêËëĒēĔĕĖėĘęĚěēȄȅȆɆȇɇȨȩ]"), Qt::CaseInsensitive);
+        letters['f'] = QRegExp(QString::fromUtf8("[ſƑƒꜰ]"), Qt::CaseInsensitive);
+        letters['g'] = QRegExp(QString::fromUtf8("[ĠġĢģĜĝĞğƓǤǴǥǵǦǧ]"), Qt::CaseInsensitive);
+        letters['h'] = QRegExp(QString::fromUtf8("[ħĤĥĦȞȟⱧⱨ]"), Qt::CaseInsensitive);
+        letters['i'] = QRegExp(QString::fromUtf8("[ÌìÍíÎîÏïİijĨĩĪīĬĭĮįǐƗȈȉȊȋǏꟾ]"), Qt::CaseInsensitive);
+        letters['j'] = QRegExp(QString::fromUtf8("[ĴĵǰȷɈɉⱼ]"), Qt::CaseInsensitive);
+        letters['k'] = QRegExp(QString::fromUtf8("[ĶķĸƘǨƙǩⱩⱪ]"), Qt::CaseInsensitive);
+        letters['l'] = QRegExp(QString::fromUtf8("[ŀŁłĹĺĻļĽľĿȴȽⱠⱡⱢꝈ]"), Qt::CaseInsensitive);
+        letters['m'] = QRegExp(QString::fromUtf8("[Ɱ]"), Qt::CaseInsensitive);
+        letters['n'] = QRegExp(QString::fromUtf8("[ÑñŃńŅņŇňʼnŊŋȵǸǹƝ]"), Qt::CaseInsensitive);
+        letters['o'] = QRegExp(QString::fromUtf8("[ÒòÓóÔÕõÖöØøŐőœŌōŎŏƠȰơǑȱǒǪȪǫȫǬȌȬǭȍȭǾȎȮǿȏȯⱺ]"), Qt::CaseInsensitive);
+        letters['p'] = QRegExp(QString::fromUtf8("[ƤƥⱣ]"), Qt::CaseInsensitive);
+        letters['q'] = QRegExp(QString::fromUtf8("[Ɋɋ]"), Qt::CaseInsensitive);
+        letters['r'] = QRegExp(QString::fromUtf8("[ŕŖŖŗŘřȐȑȒȓɌɍⱤ]"), Qt::CaseInsensitive);
+        letters['s'] = QRegExp(QString::fromUtf8("[ߊšŚśŜŝŞşȘșȿꜱ]"), Qt::CaseInsensitive);
+        letters['t'] = QRegExp(QString::fromUtf8("[ŢţŤťŦŧȶȚƫțƬƮȾⱦ]"), Qt::CaseInsensitive);
+        letters['u'] = QRegExp(QString::fromUtf8("[ÙùÚúÛûÜüŰűŲųŨũŪūŬŮůưǓǔȔɄǕȕǖȖǗȗǘǙǚǛǜƯ]"), Qt::CaseInsensitive);
+        letters['v'] = QRegExp(QString::fromUtf8("[Ʋⱱⱴⱽ]"), Qt::CaseInsensitive);
+        letters['w'] = QRegExp(QString::fromUtf8("[ŴŵⱲⱳ]"), Qt::CaseInsensitive);
+        letters['y'] = QRegExp(QString::fromUtf8("[ÿÝýŶŷŸȲƳȳƴɎɏ]"), Qt::CaseInsensitive);
+        letters['z'] = QRegExp(QString::fromUtf8("[ŹźŻżŽžɀȤƵȥƶⱫⱬ]"), Qt::CaseInsensitive);
+        noLetter = QRegExp("[^-a-z '\"]", Qt::CaseInsensitive);
     }
 };
 
index f3fde62..f2d8c5a 100644 (file)
@@ -125,7 +125,7 @@ protected:
         return string;
     }
 
-    void initAccents() { AccentsNormalizer::initAccents(); }
+    //void initAccents() { AccentsNormalizer::initAccents(); }
 
 
 
index 4ed34dd..2d7ad26 100644 (file)
@@ -85,6 +85,7 @@ QList<Translation*> XdxfPlugin::searchWordList(QString word, int limit) {
     if(word.indexOf("*")==-1 && word.indexOf("?")==-1 && word.indexOf("_")==-1
        && word.indexOf("%")==-1)
         word+="*";
+
     if(isCached())
         return searchWordListCache(word,limit);
     return searchWordListFile(word, limit);
@@ -159,7 +160,6 @@ QList<Translation*> XdxfPlugin::searchWordListFile(QString word, int limit) {
     QXmlStreamReader reader(&dictionaryFile);
     /*search words list*/
     QString a;
-
     int i=0;
     while(!reader.atEnd() && !stopped){
         reader.readNextStartElement();
index 58aeb02..92662cd 100644 (file)
@@ -80,7 +80,7 @@ void XdxfTest::searchWordListCache(){
 
     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
     if(te.size()>0)
-        QCOMPARE(te.size(), 9);
+        QCOMPARE(te.size(), 1);
     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
     QCOMPARE(te2.size(), 5);
 
@@ -123,7 +123,7 @@ void XdxfTest::searchWordListFile() {
 
     QList<Translation*> te = xdxfPlugin->searchWordList(".", 10);
     if(te.size()>0)
-        QCOMPARE(te.size(), 9);
+        QCOMPARE(te.size(), 1);
     QList<Translation*> te2 = xdxfPlugin->searchWordList("1",10);
     QCOMPARE(te2.size(), 5);
 
@@ -275,6 +275,19 @@ void XdxfTest::timeFile()
     File.close();
 }
 
+void XdxfTest::removeAccents()
+{
+    Cheat cheat;
+    cheat.settings()->setValue(QString("strip_accents"), QString("true"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("nóżka")), QString("nozka"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("motor")), QString("motor"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("nÓżKa")), QString("nozka"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("ławka")), QString("lawka"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("éàèùâêîôûëïüÿäöüç")), QString("eaeuaeioueiuyaouc"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("íőűúó")), QString("iouuo"));
+    QCOMPARE(cheat.getRemoveAccents(QString::fromUtf8("-ę")), QString("-e"));
+}
+
 
 QTEST_MAIN(XdxfTest)
 //#include "testqstring.moc"
index 70f540c..82a0f85 100644 (file)
      void searchWordListCache();
      void timeCache();
      void timeFile();
+     void removeAccents();
+ };
+
+ class Cheat : public XdxfPlugin
+ {
+    public:
+     Cheat(QObject *parent = 0) : XdxfPlugin(parent){}
+
+     QMap<QChar, QRegExp> getLetters()
+     {
+         return letters;
+     }
+
+     QString getRemoveAccents(QString s)
+     {
+         return removeAccents(s);
+     }
  };