|
|
@ -50,48 +50,51 @@ DownloadRule::DownloadRule() |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DownloadRule::matches(const QString &articleTitle) const |
|
|
|
bool DownloadRule::matches(const QString &articleTitle, const QString &expression) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
QRegExp whitespace("\\s+"); |
|
|
|
static QRegExp whitespace("\\s+"); |
|
|
|
|
|
|
|
|
|
|
|
if (!m_mustContain.empty()) { |
|
|
|
|
|
|
|
bool logged = false; |
|
|
|
|
|
|
|
bool foundMustContain = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
|
|
|
if (expression.isEmpty()) { |
|
|
|
// Accept if any complete expression matches.
|
|
|
|
// A regex of the form "expr|" will always match, so do the same for wildcards
|
|
|
|
foreach (const QString &expression, m_mustContain) { |
|
|
|
return true; |
|
|
|
if (expression.isEmpty()) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!logged) { |
|
|
|
|
|
|
|
qDebug() << "Checking matching expressions:" << m_mustContain.join("|"); |
|
|
|
|
|
|
|
logged = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (m_useRegex) { |
|
|
|
if (m_useRegex) { |
|
|
|
|
|
|
|
QRegExp reg(expression, Qt::CaseInsensitive, QRegExp::RegExp); |
|
|
|
QRegExp reg(expression, Qt::CaseInsensitive, QRegExp::RegExp); |
|
|
|
|
|
|
|
return reg.indexIn(articleTitle) > -1; |
|
|
|
if (reg.indexIn(articleTitle) > -1) |
|
|
|
|
|
|
|
foundMustContain = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
// Only accept if every wildcard token (separated by spaces) is present in the article name.
|
|
|
|
// Only match if every wildcard token (separated by spaces) is present in the article name.
|
|
|
|
// Order of wildcard tokens is unimportant (if order is important, they should have used *).
|
|
|
|
// Order of wildcard tokens is unimportant (if order is important, they should have used *).
|
|
|
|
foundMustContain = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (const QString &wildcard, expression.split(whitespace, QString::SplitBehavior::SkipEmptyParts)) { |
|
|
|
foreach (const QString &wildcard, expression.split(whitespace, QString::SplitBehavior::SkipEmptyParts)) { |
|
|
|
QRegExp reg(wildcard, Qt::CaseInsensitive, QRegExp::Wildcard); |
|
|
|
QRegExp reg(wildcard, Qt::CaseInsensitive, QRegExp::Wildcard); |
|
|
|
|
|
|
|
|
|
|
|
if (reg.indexIn(articleTitle) == -1) { |
|
|
|
if (reg.indexIn(articleTitle) == -1) |
|
|
|
foundMustContain = false; |
|
|
|
return false; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DownloadRule::matches(const QString &articleTitle) const |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!m_mustContain.empty()) { |
|
|
|
|
|
|
|
bool logged = false; |
|
|
|
|
|
|
|
bool foundMustContain = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
|
|
|
|
|
|
|
// Accept if any complete expression matches.
|
|
|
|
|
|
|
|
foreach (const QString &expression, m_mustContain) { |
|
|
|
|
|
|
|
if (!logged) { |
|
|
|
|
|
|
|
qDebug() << "Checking matching" << (m_useRegex ? "regex:" : "wildcard expressions:") << m_mustContain.join("|"); |
|
|
|
|
|
|
|
logged = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A regex of the form "expr|" will always match, so do the same for wildcards
|
|
|
|
|
|
|
|
foundMustContain = matches(articleTitle, expression); |
|
|
|
|
|
|
|
|
|
|
|
if (foundMustContain) { |
|
|
|
if (foundMustContain) { |
|
|
|
qDebug() << "Found matching expression:" << expression; |
|
|
|
qDebug() << "Found matching" << (m_useRegex ? "regex:" : "wildcard expression:") << expression; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -106,38 +109,14 @@ bool DownloadRule::matches(const QString &articleTitle) const |
|
|
|
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
|
|
|
// Each expression is either a regex, or a set of wildcards separated by whitespace.
|
|
|
|
// Reject if any complete expression matches.
|
|
|
|
// Reject if any complete expression matches.
|
|
|
|
foreach (const QString &expression, m_mustNotContain) { |
|
|
|
foreach (const QString &expression, m_mustNotContain) { |
|
|
|
if (expression.isEmpty()) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!logged) { |
|
|
|
if (!logged) { |
|
|
|
qDebug() << "Checking not matching expressions:" << m_mustNotContain.join("|"); |
|
|
|
qDebug() << "Checking not matching" << (m_useRegex ? "regex:" : "wildcard expressions:") << m_mustNotContain.join("|"); |
|
|
|
logged = true; |
|
|
|
logged = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m_useRegex) { |
|
|
|
// A regex of the form "expr|" will always match, so do the same for wildcards
|
|
|
|
QRegExp reg(expression, Qt::CaseInsensitive, QRegExp::RegExp); |
|
|
|
if (matches(articleTitle, expression)) { |
|
|
|
|
|
|
|
qDebug() << "Found not matching" << (m_useRegex ? "regex:" : "wildcard expression:") << expression; |
|
|
|
if (reg.indexIn(articleTitle) > -1) { |
|
|
|
|
|
|
|
qDebug() << "Found not matching expression:" << expression; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only reject if every wildcard token (separated by spaces) is present in the article name.
|
|
|
|
|
|
|
|
// Order of wildcard tokens is unimportant (if order is important, they should have used *).
|
|
|
|
|
|
|
|
bool foundMustNotContain = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (const QString &wildcard, expression.split(whitespace, QString::SplitBehavior::SkipEmptyParts)) { |
|
|
|
|
|
|
|
QRegExp reg(wildcard, Qt::CaseInsensitive, QRegExp::Wildcard); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (reg.indexIn(articleTitle) == -1) { |
|
|
|
|
|
|
|
foundMustNotContain = false; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (foundMustNotContain) { |
|
|
|
|
|
|
|
qDebug()<< "Found not matching expression:" << expression; |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -241,6 +220,10 @@ void DownloadRule::setMustContain(const QString &tokens) |
|
|
|
m_mustContain = QStringList() << tokens; |
|
|
|
m_mustContain = QStringList() << tokens; |
|
|
|
else |
|
|
|
else |
|
|
|
m_mustContain = tokens.split("|"); |
|
|
|
m_mustContain = tokens.split("|"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for single empty string - if so, no condition
|
|
|
|
|
|
|
|
if ((m_mustContain.size() == 1) && m_mustContain[0].isEmpty()) |
|
|
|
|
|
|
|
m_mustContain.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DownloadRule::setMustNotContain(const QString &tokens) |
|
|
|
void DownloadRule::setMustNotContain(const QString &tokens) |
|
|
@ -249,6 +232,10 @@ void DownloadRule::setMustNotContain(const QString &tokens) |
|
|
|
m_mustNotContain = QStringList() << tokens; |
|
|
|
m_mustNotContain = QStringList() << tokens; |
|
|
|
else |
|
|
|
else |
|
|
|
m_mustNotContain = tokens.split("|"); |
|
|
|
m_mustNotContain = tokens.split("|"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for single empty string - if so, no condition
|
|
|
|
|
|
|
|
if ((m_mustNotContain.size() == 1) && m_mustNotContain[0].isEmpty()) |
|
|
|
|
|
|
|
m_mustNotContain.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QStringList DownloadRule::rssFeeds() const |
|
|
|
QStringList DownloadRule::rssFeeds() const |
|
|
|