Fixed a bug that caused Eniro search results to sometimes have phone number in street...
[jenirok] / src / common / source.cpp
index 49fc999..460f98e 100644 (file)
@@ -86,7 +86,7 @@ void Source::getSources(QList<SourceDetails>& list)
 }
 
 Source::Source(QObject* parent): QObject(parent),
-maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(false),
+maxResults_(DEFAULT_MAX_RESULTS), timeout_(0), timerId_(0), findNumber_(true),
 error_(NO_ERROR), loggedIn_(false)
 {
     connect(&http_, SIGNAL(requestFinished(int, bool)), this, SLOT(httpReady(int, bool)));
@@ -366,6 +366,26 @@ QString& Source::htmlEntityDecode(QString& string)
         string = string.replace("&" + entities[i] + ";", QChar(entityValues[i]));
     }
 
+    static QRegExp entityCleaner("&#([0-9]{1,3});");
+    entityCleaner.setMinimal(true);
+
+    int pos = 0;
+
+    while((pos = entityCleaner.indexIn(string, pos)) != -1)
+    {
+        QString match = entityCleaner.cap(1);
+
+        int value = match.toInt();
+
+        if(value >= 1 && value <= 255)
+        {
+            string = string.replace(pos, match.length() + 3, QChar(value));
+        }
+
+        pos += entityCleaner.matchedLength();
+    }
+
+
    return string;
 }
 
@@ -375,6 +395,12 @@ void Source::fixUrl(QUrl& url)
     url.setEncodedQuery(path);
 }
 
+bool Source::isPhoneNumber(QString const& string)
+{
+    static QRegExp check("^([0-9 -]{7,25})$");
+    return check.exactMatch(string);
+}
+
 Source::SearchDetails::SearchDetails(QString const& q,
                                      QString const& loc,
                                      SearchType t)