diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 9082b99e8..f5d6de5b4 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -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 diff --git a/src/lib/adblock/adblockrule.cpp b/src/lib/adblock/adblockrule.cpp index c3a7658ae..8c7f94eeb 100644 --- a/src/lib/adblock/adblockrule.cpp +++ b/src/lib/adblock/adblockrule.cpp @@ -47,7 +47,6 @@ #include "adblockrule.h" #include "adblocksubscription.h" #include "qztools.h" -#include "qzregexp.h" #include #include @@ -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; diff --git a/src/lib/adblock/adblockrule.h b/src/lib/adblock/adblockrule.h index 59cc33947..c16d2b2d5 100644 --- a/src/lib/adblock/adblockrule.h +++ b/src/lib/adblock/adblockrule.h @@ -49,9 +49,9 @@ #include #include #include +#include #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 matchers; }; diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 8f037d3f4..7a1229406 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -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 #include #include +#include #ifdef Q_OS_WIN #include @@ -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); } diff --git a/src/lib/bookmarks/bookmarksimport/htmlimporter.cpp b/src/lib/bookmarks/bookmarksimport/htmlimporter.cpp index dedd0ee39..7d4ba3b91 100644 --- a/src/lib/bookmarks/bookmarksimport/htmlimporter.cpp +++ b/src/lib/bookmarks/bookmarksimport/htmlimporter.cpp @@ -17,10 +17,10 @@ * ============================================================ */ #include "htmlimporter.h" #include "bookmarkitem.h" -#include "qzregexp.h" #include #include +#include HtmlImporter::HtmlImporter(QObject* parent) : BookmarksImporter(parent) @@ -114,18 +114,15 @@ BookmarkItem* HtmlImporter::importBookmarks() if (nearest == posOfFolder) { // Next is folder - QzRegExp rx("
(.*)"); - rx.setMinimal(true); - rx.indexIn(string); - -// QString arguments = rx.cap(1); - QString folderName = rx.cap(2).trimmed(); + QRegularExpression rx(QSL("
(.*)"), 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("
(.*)"); - rx.setMinimal(true); - rx.indexIn(string); + QRegularExpression rx(QSL("
(.*)"), 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; diff --git a/src/lib/bookmarks/bookmarksimport/operaimporter.cpp b/src/lib/bookmarks/bookmarksimport/operaimporter.cpp index 0e112bdd9..8a5752542 100644 --- a/src/lib/bookmarks/bookmarksimport/operaimporter.cpp +++ b/src/lib/bookmarks/bookmarksimport/operaimporter.cpp @@ -17,7 +17,6 @@ * ============================================================ */ #include "operaimporter.h" #include "bookmarkitem.h" -#include "qzregexp.h" #include #include diff --git a/src/lib/opensearch/opensearchengine.cpp b/src/lib/opensearch/opensearchengine.cpp index 16e2c9726..08febc1fa 100644 --- a/src/lib/opensearch/opensearchengine.cpp +++ b/src/lib/opensearch/opensearchengine.cpp @@ -35,7 +35,6 @@ * ============================================================ */ #include "opensearchengine.h" -#include "qzregexp.h" #include "opensearchenginedelegate.h" #include @@ -43,7 +42,7 @@ #include #include #include -#include +#include #include #include @@ -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; diff --git a/src/lib/preferences/thememanager.cpp b/src/lib/preferences/thememanager.cpp index 156bf8197..bbeccbebe 100644 --- a/src/lib/preferences/thememanager.cpp +++ b/src/lib/preferences/thememanager.cpp @@ -22,10 +22,10 @@ #include "datapaths.h" #include "licenseviewer.h" #include "preferences.h" -#include "qzregexp.h" -#include #include +#include +#include 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; diff --git a/src/lib/tools/qzregexp.cpp b/src/lib/tools/qzregexp.cpp deleted file mode 100644 index 473ea2257..000000000 --- a/src/lib/tools/qzregexp.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 . -* ============================================================ */ -#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(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); -} - diff --git a/src/lib/tools/qzregexp.h b/src/lib/tools/qzregexp.h deleted file mode 100644 index 3f84b513a..000000000 --- a/src/lib/tools/qzregexp.h +++ /dev/null @@ -1,44 +0,0 @@ -/* ============================================================ -* Falkon - Qt web browser -* Copyright (C) 2013-2014 David Rosca -* -* 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 . -* ============================================================ */ -#ifndef QZREGEXP_H -#define QZREGEXP_H - -#include -#include - -#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 diff --git a/src/plugins/GreaseMonkey/gm_downloader.cpp b/src/plugins/GreaseMonkey/gm_downloader.cpp index 893488853..df26b1a96 100644 --- a/src/plugins/GreaseMonkey/gm_downloader.cpp +++ b/src/plugins/GreaseMonkey/gm_downloader.cpp @@ -23,7 +23,6 @@ #include "mainapplication.h" #include "networkmanager.h" #include "qztools.h" -#include "qzregexp.h" #include #include