mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Remove QzRegExp
Port directly to QRegularExpression everywhere
This commit is contained in:
parent
f1c7c2beaf
commit
4a1d807fec
@ -212,7 +212,6 @@ set(SRCS ${SRCS}
|
||||
tools/menubar.cpp
|
||||
tools/pagethumbnailer.cpp
|
||||
tools/progressbar.cpp
|
||||
tools/qzregexp.cpp
|
||||
tools/qztools.cpp
|
||||
tools/removeitemfocusdelegate.cpp
|
||||
tools/scripts.cpp
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include "adblockrule.h"
|
||||
#include "adblocksubscription.h"
|
||||
#include "qztools.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
@ -561,7 +560,10 @@ void AdBlockRule::parseFilter()
|
||||
|
||||
m_type = RegExpMatchRule;
|
||||
m_regExp = new RegExp;
|
||||
m_regExp->regExp = QzRegExp(parsedLine, m_caseSensitivity);
|
||||
m_regExp->regExp = QRegularExpression(parsedLine, QRegularExpression::InvertedGreedinessOption);
|
||||
if (m_caseSensitivity == Qt::CaseInsensitive) {
|
||||
m_regExp->regExp.setPatternOptions(m_regExp->regExp.patternOptions() | QRegularExpression::CaseInsensitiveOption);
|
||||
}
|
||||
m_regExp->matchers = createStringMatchers(parseRegExpFilter(parsedLine));
|
||||
return;
|
||||
}
|
||||
@ -595,14 +597,17 @@ void AdBlockRule::parseFilter()
|
||||
}
|
||||
|
||||
// If we still find a wildcard (*) or separator (^) or (|)
|
||||
// we must modify parsedLine to comply with QzRegExp
|
||||
// we must modify parsedLine to comply with QRegularExpression
|
||||
if (parsedLine.contains(QL1C('*')) ||
|
||||
parsedLine.contains(QL1C('^')) ||
|
||||
parsedLine.contains(QL1C('|'))
|
||||
) {
|
||||
m_type = RegExpMatchRule;
|
||||
m_regExp = new RegExp;
|
||||
m_regExp->regExp = QzRegExp(createRegExpFromFilter(parsedLine), m_caseSensitivity);
|
||||
m_regExp->regExp = QRegularExpression(createRegExpFromFilter(parsedLine), QRegularExpression::InvertedGreedinessOption);
|
||||
if (m_caseSensitivity == Qt::CaseInsensitive) {
|
||||
m_regExp->regExp.setPatternOptions(m_regExp->regExp.patternOptions() | QRegularExpression::CaseInsensitiveOption);
|
||||
}
|
||||
m_regExp->matchers = createStringMatchers(parseRegExpFilter(parsedLine));
|
||||
return;
|
||||
}
|
||||
@ -766,7 +771,7 @@ bool AdBlockRule::stringMatch(const QString &domain, const QString &encodedUrl)
|
||||
if (!isMatchingRegExpStrings(encodedUrl)) {
|
||||
return false;
|
||||
}
|
||||
return (m_regExp->regExp.indexIn(encodedUrl) != -1);
|
||||
return m_regExp->regExp.match(encodedUrl).hasMatch();
|
||||
|
||||
case MatchAllUrlsRule:
|
||||
return true;
|
||||
|
@ -49,9 +49,9 @@
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QStringMatcher>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "qzcommon.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
class QUrl;
|
||||
class QWebEngineUrlRequestInfo;
|
||||
@ -181,7 +181,7 @@ private:
|
||||
QStringList m_blockedDomains;
|
||||
|
||||
struct RegExp {
|
||||
QzRegExp regExp;
|
||||
QRegularExpression regExp;
|
||||
QList<QStringMatcher> matchers;
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "updater.h"
|
||||
#include "autofill.h"
|
||||
#include "settings.h"
|
||||
#include "qzregexp.h"
|
||||
#include "autosaver.h"
|
||||
#include "datapaths.h"
|
||||
#include "tabwidget.h"
|
||||
@ -65,6 +64,7 @@
|
||||
#include <QWebEngineProfile>
|
||||
#include <QWebEngineDownloadItem>
|
||||
#include <QWebEngineScriptCollection>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QtWin>
|
||||
@ -1028,7 +1028,7 @@ void MainApplication::loadTheme(const QString &name)
|
||||
qss.append(QzTools::readAllFileContents(DataPaths::currentProfilePath() + QL1S("/userChrome.css")));
|
||||
|
||||
QString relativePath = QDir::current().relativeFilePath(activeThemePath);
|
||||
qss.replace(QzRegExp(QSL("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)"), Qt::CaseSensitive), QString("url(%1/\\1)").arg(relativePath));
|
||||
qss.replace(QRegularExpression(QSL("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)")), QString("url(%1/\\1)").arg(relativePath));
|
||||
setStyleSheet(qss);
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,10 @@
|
||||
* ============================================================ */
|
||||
#include "htmlimporter.h"
|
||||
#include "bookmarkitem.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QFileDialog>
|
||||
#include <QRegularExpression>
|
||||
|
||||
HtmlImporter::HtmlImporter(QObject* parent)
|
||||
: BookmarksImporter(parent)
|
||||
@ -114,18 +114,15 @@ BookmarkItem* HtmlImporter::importBookmarks()
|
||||
|
||||
if (nearest == posOfFolder) {
|
||||
// Next is folder
|
||||
QzRegExp rx("<dt><h3(.*)>(.*)</h3>");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(string);
|
||||
|
||||
// QString arguments = rx.cap(1);
|
||||
QString folderName = rx.cap(2).trimmed();
|
||||
QRegularExpression rx(QSL("<dt><h3(.*)>(.*)</h3>"), QRegularExpression::InvertedGreedinessOption | QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpressionMatch match = rx.match(string);
|
||||
QString folderName = match.captured(2).trimmed();
|
||||
|
||||
BookmarkItem* folder = new BookmarkItem(BookmarkItem::Folder, folders.isEmpty() ? root : folders.last());
|
||||
folder->setTitle(folderName);
|
||||
folders.append(folder);
|
||||
|
||||
start += posOfFolder + rx.cap(0).size();
|
||||
start += posOfFolder + match.captured(0).size();
|
||||
}
|
||||
else if (nearest == posOfEndFolder) {
|
||||
// Next is end of folder
|
||||
@ -137,20 +134,18 @@ BookmarkItem* HtmlImporter::importBookmarks()
|
||||
}
|
||||
else {
|
||||
// Next is link
|
||||
QzRegExp rx("<dt><a(.*)>(.*)</a>");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(string);
|
||||
QRegularExpression rx(QSL("<dt><a(.*)>(.*)</a>"), QRegularExpression::InvertedGreedinessOption | QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpressionMatch match = rx.match(string);
|
||||
|
||||
QString arguments = rx.cap(1);
|
||||
QString linkName = rx.cap(2).trimmed();
|
||||
QString arguments = match.captured(1);
|
||||
QString linkName = match.captured(2).trimmed();
|
||||
|
||||
QzRegExp rx2("href=\"(.*)\"");
|
||||
rx2.setMinimal(true);
|
||||
rx2.indexIn(arguments);
|
||||
QRegularExpression rx2(QSL("href=\"(.*)\""), QRegularExpression::InvertedGreedinessOption | QRegularExpression::DotMatchesEverythingOption);
|
||||
QRegularExpressionMatch match2 = rx2.match(arguments);
|
||||
|
||||
QUrl url = QUrl::fromEncoded(rx2.cap(1).trimmed().toUtf8());
|
||||
QUrl url = QUrl::fromEncoded(match2.captured(1).trimmed().toUtf8());
|
||||
|
||||
start += posOfLink + rx.cap(0).size();
|
||||
start += posOfLink + match.captured(0).size();
|
||||
|
||||
if (url.isEmpty() || url.scheme() == QL1S("place") || url.scheme() == QL1S("about"))
|
||||
continue;
|
||||
|
@ -17,7 +17,6 @@
|
||||
* ============================================================ */
|
||||
#include "operaimporter.h"
|
||||
#include "bookmarkitem.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QUrl>
|
||||
#include <QDir>
|
||||
|
@ -35,7 +35,6 @@
|
||||
* ============================================================ */
|
||||
|
||||
#include "opensearchengine.h"
|
||||
#include "qzregexp.h"
|
||||
#include "opensearchenginedelegate.h"
|
||||
|
||||
#include <qbuffer.h>
|
||||
@ -43,7 +42,7 @@
|
||||
#include <qlocale.h>
|
||||
#include <qnetworkrequest.h>
|
||||
#include <qnetworkreply.h>
|
||||
#include <qregexp.h>
|
||||
#include <qregularexpression.h>
|
||||
#include <qstringlist.h>
|
||||
|
||||
#include <QUrlQuery>
|
||||
@ -132,7 +131,7 @@ QString OpenSearchEngine::parseTemplate(const QString &searchTerm, const QString
|
||||
result.replace(QLatin1String("{language}"), language);
|
||||
result.replace(QLatin1String("{inputEncoding}"), QLatin1String("UTF-8"));
|
||||
result.replace(QLatin1String("{outputEncoding}"), QLatin1String("UTF-8"));
|
||||
result.replace(QzRegExp(QLatin1String("\\{([^\\}]*:|)source\\??\\}")), QCoreApplication::applicationName());
|
||||
result.replace(QRegularExpression(QSL("\\{([^\\}]*:|)source\\??\\}")), QCoreApplication::applicationName());
|
||||
result.replace(QLatin1String("{searchTerms}"), QLatin1String(QUrl::toPercentEncoding(searchTerm)));
|
||||
|
||||
return result;
|
||||
|
@ -22,10 +22,10 @@
|
||||
#include "datapaths.h"
|
||||
#include "licenseviewer.h"
|
||||
#include "preferences.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QTextBrowser>
|
||||
#include <QDir>
|
||||
#include <QTextBrowser>
|
||||
#include <QRegularExpression>
|
||||
|
||||
ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences)
|
||||
: QWidget()
|
||||
@ -123,33 +123,32 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &path, const QString
|
||||
|
||||
QString theme_info = QzTools::readAllFileContents(path + "theme.info");
|
||||
|
||||
QzRegExp rx("Name:(.*)\\n");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(theme_info);
|
||||
if (rx.captureCount() == 1) {
|
||||
info.name = rx.cap(1).trimmed();
|
||||
QRegularExpression rx(QSL("Name:(.*)\\n"));
|
||||
QRegularExpressionMatch match = rx.match(theme_info);
|
||||
if (match.hasMatch()) {
|
||||
info.name = match.captured(1).trimmed();
|
||||
}
|
||||
|
||||
if (info.name.isEmpty() || m_themeHash.contains(info.name)) {
|
||||
return info;
|
||||
}
|
||||
|
||||
rx.setPattern("Author:(.*)\\n");
|
||||
rx.indexIn(theme_info);
|
||||
if (rx.captureCount() == 1) {
|
||||
info.author = rx.cap(1).trimmed();
|
||||
rx.setPattern(QSL("Author:(.*)\\n"));
|
||||
match = rx.match(theme_info);
|
||||
if (match.hasMatch()) {
|
||||
info.author = match.captured(1).trimmed();
|
||||
}
|
||||
|
||||
rx.setPattern("Short Description:(.*)\\n");
|
||||
rx.indexIn(theme_info);
|
||||
if (rx.captureCount() == 1) {
|
||||
info.shortDescription = rx.cap(1).trimmed();
|
||||
rx.setPattern(QSL("Short Description:(.*)\\n"));
|
||||
match = rx.match(theme_info);
|
||||
if (match.hasMatch()) {
|
||||
info.shortDescription = match.captured(1).trimmed();
|
||||
}
|
||||
|
||||
rx.setPattern("Long Description:(.*)\\n");
|
||||
rx.indexIn(theme_info);
|
||||
if (rx.captureCount() == 1) {
|
||||
info.longDescription = rx.cap(1).trimmed();
|
||||
rx.setPattern(QSL("Long Description:(.*)\\n"));
|
||||
match = rx.match(theme_info);
|
||||
if (match.hasMatch()) {
|
||||
info.longDescription = match.captured(1).trimmed();
|
||||
}
|
||||
|
||||
info.isValid = true;
|
||||
|
@ -1,85 +0,0 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "qzregexp.h"
|
||||
#include "qztools.h"
|
||||
|
||||
QzRegExp::QzRegExp()
|
||||
: QRegularExpression(QString(), QRegularExpression::DotMatchesEverythingOption)
|
||||
, m_matchedLength(-1)
|
||||
{
|
||||
}
|
||||
|
||||
QzRegExp::QzRegExp(const QString &pattern, Qt::CaseSensitivity cs)
|
||||
: QRegularExpression(pattern, QRegularExpression::DotMatchesEverythingOption)
|
||||
, m_matchedLength(-1)
|
||||
{
|
||||
if (cs == Qt::CaseInsensitive) {
|
||||
setPatternOptions(patternOptions() | QRegularExpression::CaseInsensitiveOption);
|
||||
}
|
||||
}
|
||||
|
||||
QzRegExp::QzRegExp(const QzRegExp &re)
|
||||
: QRegularExpression(re)
|
||||
, m_matchedLength(-1)
|
||||
{
|
||||
}
|
||||
|
||||
void QzRegExp::setMinimal(bool minimal)
|
||||
{
|
||||
QRegularExpression::PatternOptions opt;
|
||||
|
||||
if (minimal) {
|
||||
opt = patternOptions() | QRegularExpression::InvertedGreedinessOption;
|
||||
}
|
||||
else {
|
||||
opt = patternOptions() & ~QRegularExpression::InvertedGreedinessOption;
|
||||
}
|
||||
|
||||
setPatternOptions(opt);
|
||||
}
|
||||
|
||||
int QzRegExp::indexIn(const QString &str, int offset) const
|
||||
{
|
||||
QzRegExp* that = const_cast<QzRegExp*>(this);
|
||||
QRegularExpressionMatch m = match(str, offset);
|
||||
|
||||
if (!m.hasMatch()) {
|
||||
that->m_matchedLength = -1;
|
||||
that->m_capturedTexts.clear();
|
||||
return -1;
|
||||
}
|
||||
|
||||
that->m_matchedLength = m.capturedLength();
|
||||
that->m_capturedTexts = m.capturedTexts();
|
||||
return m.capturedStart();
|
||||
}
|
||||
|
||||
int QzRegExp::matchedLength() const
|
||||
{
|
||||
return m_matchedLength;
|
||||
}
|
||||
|
||||
QString QzRegExp::cap(int nth) const
|
||||
{
|
||||
if (!QzTools::containsIndex(m_capturedTexts, nth)) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return m_capturedTexts.at(nth);
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef QZREGEXP_H
|
||||
#define QZREGEXP_H
|
||||
|
||||
#include <QRegularExpression>
|
||||
#include <QStringList>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class FALKON_EXPORT QzRegExp : public QRegularExpression
|
||||
{
|
||||
public:
|
||||
QzRegExp();
|
||||
QzRegExp(const QString &pattern, Qt::CaseSensitivity cs = Qt::CaseSensitive);
|
||||
QzRegExp(const QzRegExp &re);
|
||||
|
||||
void setMinimal(bool minimal);
|
||||
int indexIn(const QString &str, int offset = 0) const;
|
||||
int matchedLength() const;
|
||||
QString cap(int nth = 0) const;
|
||||
|
||||
private:
|
||||
QStringList m_capturedTexts;
|
||||
int m_matchedLength;
|
||||
|
||||
};
|
||||
|
||||
#endif // QZREGEXP_H
|
@ -23,7 +23,6 @@
|
||||
#include "mainapplication.h"
|
||||
#include "networkmanager.h"
|
||||
#include "qztools.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
|
Loading…
Reference in New Issue
Block a user