mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
[Qt5] Use RegExp wrapper to take advantage of new regexp engine.
QzRegExp wrapper is using QRegExp directly on Qt 4 and QRegularExpression (with PCRE engine) on Qt 5.
This commit is contained in:
parent
f32ec93caf
commit
bed43ed0c8
|
@ -48,7 +48,7 @@
|
|||
#include "adblocksubscription.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRegExp>
|
||||
#include "qzregexp.h"
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
@ -467,7 +467,7 @@ void AdBlockRule::parseFilter()
|
|||
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
||||
|
||||
m_useRegExp = true;
|
||||
m_regExp = QRegExp(parsedLine, m_caseSensitivity, QRegExp::RegExp);
|
||||
m_regExp = QzRegExp(parsedLine, m_caseSensitivity);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -482,7 +482,7 @@ void AdBlockRule::parseFilter()
|
|||
|
||||
// We can use fast string matching for domain here
|
||||
if (parsedLine.startsWith(QLatin1String("||")) && parsedLine.endsWith(QLatin1Char('^'))
|
||||
&& !parsedLine.contains(QRegExp("[/:?=&\\*]"))) {
|
||||
&& !parsedLine.contains(QzRegExp("[/:?=&\\*]"))) {
|
||||
parsedLine = parsedLine.mid(2);
|
||||
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
||||
|
||||
|
@ -492,7 +492,7 @@ void AdBlockRule::parseFilter()
|
|||
}
|
||||
|
||||
// If rule contains only | at end, we can also use string matching
|
||||
if (parsedLine.endsWith(QLatin1Char('|')) && !parsedLine.contains(QRegExp("[\\^\\*]"))
|
||||
if (parsedLine.endsWith(QLatin1Char('|')) && !parsedLine.contains(QzRegExp("[\\^\\*]"))
|
||||
&& parsedLine.count(QLatin1Char('|')) == 1) {
|
||||
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
||||
|
||||
|
@ -502,24 +502,24 @@ void AdBlockRule::parseFilter()
|
|||
}
|
||||
|
||||
// If we still find a wildcard (*) or separator (^) or (|)
|
||||
// we must modify parsedLine to comply with QRegExp
|
||||
// we must modify parsedLine to comply with QzRegExp
|
||||
if (parsedLine.contains(QLatin1Char('*')) || parsedLine.contains(QLatin1Char('^'))
|
||||
|| parsedLine.contains(QLatin1Char('|'))) {
|
||||
parsedLine.replace(QRegExp(QLatin1String("\\*+")), QLatin1String("*")) // remove multiple wildcards
|
||||
.replace(QRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder
|
||||
.replace(QRegExp(QLatin1String("^(\\*)")), QString()) // remove leading wildcards
|
||||
.replace(QRegExp(QLatin1String("(\\*)$")), QString())
|
||||
.replace(QRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols
|
||||
.replace(QRegExp(QLatin1String("^\\\\\\|\\\\\\|")),
|
||||
parsedLine.replace(QzRegExp(QLatin1String("\\*+")), QLatin1String("*")) // remove multiple wildcards
|
||||
.replace(QzRegExp(QLatin1String("\\^\\|$")), QLatin1String("^")) // remove anchors following separator placeholder
|
||||
.replace(QzRegExp(QLatin1String("^(\\*)")), QString()) // remove leading wildcards
|
||||
.replace(QzRegExp(QLatin1String("(\\*)$")), QString())
|
||||
.replace(QzRegExp(QLatin1String("(\\W)")), QLatin1String("\\\\1")) // escape special symbols
|
||||
.replace(QzRegExp(QLatin1String("^\\\\\\|\\\\\\|")),
|
||||
QLatin1String("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?")) // process extended anchor at expression start
|
||||
.replace(QRegExp(QLatin1String("\\\\\\^")),
|
||||
.replace(QzRegExp(QLatin1String("\\\\\\^")),
|
||||
QLatin1String("(?:[^\\w\\d\\-.%]|$)")) // process separator placeholders
|
||||
.replace(QRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start
|
||||
.replace(QRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end
|
||||
.replace(QRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")); // replace wildcards by .*
|
||||
.replace(QzRegExp(QLatin1String("^\\\\\\|")), QLatin1String("^")) // process anchor at expression start
|
||||
.replace(QzRegExp(QLatin1String("\\\\\\|$")), QLatin1String("$")) // process anchor at expression end
|
||||
.replace(QzRegExp(QLatin1String("\\\\\\*")), QLatin1String(".*")); // replace wildcards by .*
|
||||
|
||||
m_useRegExp = true;
|
||||
m_regExp = QRegExp(parsedLine, m_caseSensitivity, QRegExp::RegExp);
|
||||
m_regExp = QzRegExp(parsedLine, m_caseSensitivity);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,10 +47,10 @@
|
|||
#define ADBLOCKRULE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QRegExp>
|
||||
#include <QStringList>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
class QNetworkRequest;
|
||||
class QUrl;
|
||||
|
@ -111,7 +111,7 @@ private:
|
|||
bool m_domainRestricted;
|
||||
|
||||
bool m_useRegExp;
|
||||
QRegExp m_regExp;
|
||||
QzRegExp m_regExp;
|
||||
|
||||
bool m_useDomainMatch;
|
||||
bool m_useEndsMatch;
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "useragentmanager.h"
|
||||
#include "restoremanager.h"
|
||||
#include "proxystyle.h"
|
||||
#include "qzregexp.h"
|
||||
#include "checkboxdialog.h"
|
||||
#include "registerqappassociation.h"
|
||||
#include "html5permissions/html5permissionsmanager.h"
|
||||
|
@ -375,7 +376,7 @@ void MainApplication::loadSettings()
|
|||
}
|
||||
|
||||
QString relativePath = QDir::current().relativeFilePath(m_activeThemePath);
|
||||
css.replace(QRegExp("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)", Qt::CaseSensitive, QRegExp::RegExp2),
|
||||
css.replace(QzRegExp("url\\s*\\(\\s*([^\\*:\\);]+)\\s*\\)", Qt::CaseSensitive),
|
||||
QString("url(%1\\1)").arg(relativePath + "/"));
|
||||
setStyleSheet(css);
|
||||
|
||||
|
|
|
@ -1732,7 +1732,7 @@ void QupZilla::hideNavigationWithFullScreen()
|
|||
void QupZilla::hideNavigationSlot()
|
||||
{
|
||||
TabbedWebView* view = weView();
|
||||
bool mouseInView = view && view->geometry().contains(view->mapFromGlobal(QCursor::pos()));
|
||||
bool mouseInView = view && view->underMouse();
|
||||
|
||||
if (isFullScreen() && mouseInView) {
|
||||
m_navigationContainer->hide();
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "pageformcompleter.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QWebPage>
|
||||
#include <QWebFrame>
|
||||
|
@ -160,7 +161,7 @@ QByteArray PageFormCompleter::convertWebKitFormBoundaryIfNecessary(const QByteAr
|
|||
}
|
||||
|
||||
QByteArray formatedData;
|
||||
QRegExp rx("name=\"(.*)------WebKitFormBoundary");
|
||||
QzRegExp rx("name=\"(.*)------WebKitFormBoundary");
|
||||
rx.setMinimal(true);
|
||||
|
||||
int pos = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -22,7 +22,7 @@
|
|||
#include <QScriptEngine>
|
||||
#include <QScriptValue>
|
||||
#include <QScriptValueIterator>
|
||||
#include <QRegExp>
|
||||
#include "qzregexp.h"
|
||||
|
||||
ChromeImporter::ChromeImporter(QObject* parent)
|
||||
: QObject(parent)
|
||||
|
@ -57,7 +57,7 @@ QList<BookmarksModel::Bookmark> ChromeImporter::exportBookmarks()
|
|||
m_file.close();
|
||||
|
||||
QStringList parsedBookmarks;
|
||||
QRegExp rx("\\{(\\s*)\"date_added(.*)\"(\\s*)\\}", Qt::CaseSensitive);
|
||||
QzRegExp rx("\\{(\\s*)\"date_added(.*)\"(\\s*)\\}", Qt::CaseSensitive);
|
||||
rx.setMinimal(true);
|
||||
|
||||
int pos = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -18,7 +18,7 @@
|
|||
#include "htmlimporter.h"
|
||||
#include "bookmarksimportdialog.h"
|
||||
|
||||
#include <QRegExp>
|
||||
#include "qzregexp.h"
|
||||
|
||||
HtmlImporter::HtmlImporter(QObject* parent)
|
||||
: QObject(parent)
|
||||
|
@ -100,7 +100,7 @@ QList<BookmarksModel::Bookmark> HtmlImporter::exportBookmarks()
|
|||
|
||||
if (nearest == posOfFolder) {
|
||||
// Next is folder
|
||||
QRegExp rx("<dt><h3(.*)>(.*)</h3>");
|
||||
QzRegExp rx("<dt><h3(.*)>(.*)</h3>");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(string);
|
||||
|
||||
|
@ -121,14 +121,14 @@ QList<BookmarksModel::Bookmark> HtmlImporter::exportBookmarks()
|
|||
}
|
||||
else {
|
||||
// Next is link
|
||||
QRegExp rx("<dt><a(.*)>(.*)</a>");
|
||||
QzRegExp rx("<dt><a(.*)>(.*)</a>");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(string);
|
||||
|
||||
QString arguments = rx.cap(1);
|
||||
QString linkName = rx.cap(2).trimmed();
|
||||
|
||||
QRegExp rx2("href=\"(.*)\"");
|
||||
QzRegExp rx2("href=\"(.*)\"");
|
||||
rx2.setMinimal(true);
|
||||
rx2.indexIn(arguments);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -17,6 +17,7 @@
|
|||
* ============================================================ */
|
||||
#include "operaimporter.h"
|
||||
#include "bookmarksimportdialog.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
OperaImporter::OperaImporter(QObject* parent)
|
||||
: QObject(parent)
|
||||
|
@ -50,7 +51,7 @@ QList<BookmarksModel::Bookmark> OperaImporter::exportBookmarks()
|
|||
QString bookmarks = QString::fromUtf8(m_file.readAll());
|
||||
m_file.close();
|
||||
|
||||
QRegExp rx("#URL(.*)CREATED", Qt::CaseSensitive);
|
||||
QzRegExp rx("#URL(.*)CREATED", Qt::CaseSensitive);
|
||||
rx.setMinimal(true);
|
||||
|
||||
int pos = 0;
|
||||
|
@ -58,7 +59,7 @@ QList<BookmarksModel::Bookmark> OperaImporter::exportBookmarks()
|
|||
QString string = rx.cap(1);
|
||||
pos += rx.matchedLength();
|
||||
|
||||
QRegExp rx2("NAME=(.*)\\n");
|
||||
QzRegExp rx2("NAME=(.*)\\n");
|
||||
rx2.setMinimal(true);
|
||||
rx2.indexIn(string);
|
||||
QString name = rx2.cap(1).trimmed();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "downloadmanager.h"
|
||||
#include "qztools.h"
|
||||
#include "settings.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QFileIconProvider>
|
||||
#include <QListWidgetItem>
|
||||
|
@ -129,13 +130,13 @@ QString DownloadFileHelper::parseContentDisposition(const QByteArray &header)
|
|||
}
|
||||
|
||||
// We try to use UTF-8 encoded filename first if present
|
||||
if (value.contains(QRegExp("[ ;]{1,}filename*\\*\\s*=\\s*UTF-8''", Qt::CaseInsensitive))) {
|
||||
QRegExp reg("filename\\s*\\*\\s*=\\s*UTF-8''([^;]*)", Qt::CaseInsensitive);
|
||||
if (value.contains(QzRegExp("[ ;]{1,}filename*\\*\\s*=\\s*UTF-8''", Qt::CaseInsensitive))) {
|
||||
QzRegExp reg("filename\\s*\\*\\s*=\\s*UTF-8''([^;]*)", Qt::CaseInsensitive);
|
||||
reg.indexIn(value);
|
||||
path = QUrl::fromPercentEncoding(reg.cap(1).toUtf8()).trimmed();
|
||||
}
|
||||
else if (value.contains(QRegExp("[ ;]{1,}filename\\s*=", Qt::CaseInsensitive))) {
|
||||
QRegExp reg("[ ;]{1,}filename\\s*=(.*)", Qt::CaseInsensitive);
|
||||
else if (value.contains(QzRegExp("[ ;]{1,}filename\\s*=", Qt::CaseInsensitive))) {
|
||||
QzRegExp reg("[ ;]{1,}filename\\s*=(.*)", Qt::CaseInsensitive);
|
||||
reg.indexIn(value);
|
||||
path = reg.cap(1).trimmed();
|
||||
|
||||
|
@ -152,7 +153,7 @@ QString DownloadFileHelper::parseContentDisposition(const QByteArray &header)
|
|||
}
|
||||
}
|
||||
else {
|
||||
QRegExp reg("([^;]*)", Qt::CaseInsensitive);
|
||||
QzRegExp reg("([^;]*)", Qt::CaseInsensitive);
|
||||
reg.indexIn(path);
|
||||
path = reg.cap(1).trimmed();
|
||||
}
|
||||
|
|
|
@ -14,10 +14,6 @@ include(../defines.pri)
|
|||
include(../../translations/translations.pri)
|
||||
#include(../../tests/modeltest/modeltest.pri)
|
||||
|
||||
isEqual(QT_MAJOR_VERSION, 5) {
|
||||
include(3rdparty/qftp.pri)
|
||||
}
|
||||
|
||||
contains(DEFINES, USE_QTWEBKIT_2_2) {
|
||||
include(plugins/qtwebkit/qtwebkit-plugins.pri)
|
||||
}
|
||||
|
@ -215,7 +211,7 @@ SOURCES += \
|
|||
tools/menubar.cpp \
|
||||
navigation/navigationcontainer.cpp \
|
||||
tools/horizontallistwidget.cpp \
|
||||
tools/mactoolbutton.cpp
|
||||
tools/mactoolbutton.cpp \
|
||||
|
||||
HEADERS += \
|
||||
webview/tabpreview.h \
|
||||
|
@ -385,7 +381,8 @@ HEADERS += \
|
|||
tools/menubar.h \
|
||||
navigation/navigationcontainer.h \
|
||||
tools/horizontallistwidget.h \
|
||||
tools/mactoolbutton.h
|
||||
tools/mactoolbutton.h \
|
||||
tools/qzregexp.h
|
||||
|
||||
FORMS += \
|
||||
preferences/autofillmanager.ui \
|
||||
|
@ -441,6 +438,12 @@ RESOURCES += \
|
|||
data/html.qrc \
|
||||
data/data.qrc
|
||||
|
||||
isEqual(QT_MAJOR_VERSION, 5) {
|
||||
include(3rdparty/qftp.pri)
|
||||
|
||||
SOURCES += tools/qzregexp.cpp
|
||||
}
|
||||
|
||||
!mac:unix {
|
||||
target.path = $$library_folder
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -35,7 +35,7 @@
|
|||
* ============================================================ */
|
||||
|
||||
#include "opensearchengine.h"
|
||||
|
||||
#include "qzregexp.h"
|
||||
#include "opensearchenginedelegate.h"
|
||||
|
||||
#include <qbuffer.h>
|
||||
|
@ -139,7 +139,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(QRegExp(QLatin1String("\\{([^\\}]*:|)source\\??\\}")), QCoreApplication::applicationName());
|
||||
result.replace(QzRegExp(QLatin1String("\\{([^\\}]*:|)source\\??\\}")), QCoreApplication::applicationName());
|
||||
result.replace(QLatin1String("{searchTerms}"), QLatin1String(QUrl::toPercentEncoding(searchTerm)));
|
||||
|
||||
return result;
|
||||
|
|
|
@ -152,7 +152,7 @@ void SourceViewer::loadSource()
|
|||
|
||||
QString html = m_frame.data()->toHtml();
|
||||
// Remove AdBlock element hiding rules
|
||||
html.remove(QRegExp("<style type=\"text/css\">\n/\\* AdBlock for QupZilla \\*/\n.*\\{display: none !important;\\}\n</style>"));
|
||||
html.remove(QzRegExp("<style type=\"text/css\">\n/\\* AdBlock for QupZilla \\*/\n.*\\{display: none !important;\\}\n</style>"));
|
||||
m_sourceEdit->setPlainText(html);
|
||||
|
||||
// Highlight selectedHtml
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -22,6 +22,7 @@
|
|||
#include "settings.h"
|
||||
#include "licenseviewer.h"
|
||||
#include "preferences.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QTextBrowser>
|
||||
#include <QDir>
|
||||
|
@ -119,7 +120,7 @@ ThemeManager::Theme ThemeManager::parseTheme(const QString &name)
|
|||
|
||||
QString theme_info = QzTools::readAllFileContents(path + "theme.info");
|
||||
|
||||
QRegExp rx("Name:(.*)\\n");
|
||||
QzRegExp rx("Name:(.*)\\n");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(theme_info);
|
||||
if (rx.captureCount() == 1) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -67,7 +67,7 @@ HtmlHighlighter::HtmlHighlighter(QTextDocument* parent)
|
|||
QStringList keywordPatterns;
|
||||
keywordPatterns << "</?([A-Za-z:0-9]{1,20})/?(>| )?" << ">" << "(<!DOCTYPE html>|<!DOCTYPE html PUBLIC)";
|
||||
foreach(const QString & pattern, keywordPatterns) {
|
||||
rule.pattern = QRegExp(pattern);
|
||||
rule.pattern = QzRegExp(pattern);
|
||||
rule.format = tagFormat;
|
||||
highlightingRules.append(rule);
|
||||
}
|
||||
|
@ -75,13 +75,13 @@ HtmlHighlighter::HtmlHighlighter(QTextDocument* parent)
|
|||
// options: <tag option1="" option2="">
|
||||
tagOptionsFormat.setForeground(Qt::black);
|
||||
tagOptionsFormat.setFontWeight(QFont::Bold);
|
||||
rule.pattern = QRegExp("(\\S{2,20})=\"");
|
||||
rule.pattern = QzRegExp("(\\S{2,20})=\"");
|
||||
rule.format = tagOptionsFormat;
|
||||
highlightingRules.append(rule);
|
||||
|
||||
// " " strings
|
||||
quotationFormat.setForeground(Qt::darkGreen);
|
||||
QRegExp rx("\".*\"");
|
||||
QzRegExp rx("\".*\"");
|
||||
rx.setMinimal(true);
|
||||
rule.pattern = rx;
|
||||
rule.format = quotationFormat;
|
||||
|
@ -89,14 +89,14 @@ HtmlHighlighter::HtmlHighlighter(QTextDocument* parent)
|
|||
|
||||
// <!-- --> comments
|
||||
multiLineCommentFormat.setForeground(Qt::gray);
|
||||
commentStartExpression = QRegExp("<!--");
|
||||
commentEndExpression = QRegExp("-->");
|
||||
commentStartExpression = QzRegExp("<!--");
|
||||
commentEndExpression = QzRegExp("-->");
|
||||
}
|
||||
|
||||
void HtmlHighlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
foreach(const HighlightingRule & rule, highlightingRules) {
|
||||
QRegExp expression(rule.pattern);
|
||||
QzRegExp expression(rule.pattern);
|
||||
int index = expression.indexIn(text);
|
||||
while (index >= 0) {
|
||||
int length = expression.matchedLength();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -62,6 +62,7 @@
|
|||
#include <QTextCharFormat>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
class QTextDocument;
|
||||
|
||||
|
@ -75,14 +76,14 @@ protected:
|
|||
|
||||
private:
|
||||
struct HighlightingRule {
|
||||
QRegExp pattern;
|
||||
QzRegExp pattern;
|
||||
QTextCharFormat format;
|
||||
};
|
||||
|
||||
QVector<HighlightingRule> highlightingRules;
|
||||
|
||||
QRegExp commentStartExpression;
|
||||
QRegExp commentEndExpression;
|
||||
QzRegExp commentStartExpression;
|
||||
QzRegExp commentEndExpression;
|
||||
|
||||
QTextCharFormat tagFormat;
|
||||
QTextCharFormat tagOptionsFormat;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2010-2013 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
|
||||
|
@ -15,9 +15,11 @@
|
|||
* 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 <QNetworkReply>
|
||||
#include "iconfetcher.h"
|
||||
#include "followredirectreply.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
||||
IconFetcher::IconFetcher(QObject* parent)
|
||||
: QObject(parent)
|
||||
|
@ -48,7 +50,7 @@ void IconFetcher::pageDownloaded()
|
|||
QUrl replyUrl = reply->url();
|
||||
reply->deleteLater();
|
||||
|
||||
QRegExp rx("<link(.*)>", Qt::CaseInsensitive);
|
||||
QzRegExp rx("<link(.*)>", Qt::CaseInsensitive);
|
||||
rx.setMinimal(true);
|
||||
|
||||
QString shortcutIconTag;
|
||||
|
@ -72,7 +74,7 @@ void IconFetcher::pageDownloaded()
|
|||
newReply = new FollowRedirectReply(faviconUrl, m_manager);
|
||||
}
|
||||
else {
|
||||
QRegExp rx("href=\"(.*)\"", Qt::CaseInsensitive);
|
||||
QzRegExp rx("href=\"(.*)\"", Qt::CaseInsensitive);
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(shortcutIconTag);
|
||||
QUrl url = QUrl(rx.cap(1));
|
||||
|
|
87
src/lib/tools/qzregexp.cpp
Normal file
87
src/lib/tools/qzregexp.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013 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"
|
||||
|
||||
#if (QT_VERSION >= 0x050000)
|
||||
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::listContainsIndex(m_capturedTexts, nth)) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return m_capturedTexts.at(nth);
|
||||
}
|
||||
#endif // (QT_VERSION >= 0x050000)
|
||||
|
52
src/lib/tools/qzregexp.h
Normal file
52
src/lib/tools/qzregexp.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2013 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 <QObject> // Needed for QT_VERSION
|
||||
|
||||
#if (QT_VERSION < 0x050000)
|
||||
// Qt 4 - use QRegExp directly
|
||||
#include <QRegExp>
|
||||
#define QzRegExp QRegExp
|
||||
#else // Qt 5
|
||||
#include <QRegularExpression>
|
||||
#include <QStringList>
|
||||
|
||||
#include "qz_namespace.h"
|
||||
|
||||
class QT_QUPZILLA_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 // Qt 5
|
||||
|
||||
#endif // QZREGEXP_H
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2012-2013 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
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
#include <QRegExp>
|
||||
#include "qzregexp.h"
|
||||
#include <QDebug>
|
||||
|
||||
GM_Downloader::GM_Downloader(const QNetworkRequest &request, GM_Manager* manager)
|
||||
|
@ -72,7 +72,7 @@ void GM_Downloader::scriptDownloaded()
|
|||
QSettings settings(m_manager->settinsPath() + "greasemonkey/requires/requires.ini", QSettings::IniFormat);
|
||||
settings.beginGroup("Files");
|
||||
|
||||
QRegExp rx("@require(.*)\\n");
|
||||
QzRegExp rx("@require(.*)\\n");
|
||||
rx.setMinimal(true);
|
||||
rx.indexIn(response);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "gm_manager.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QRegExp>
|
||||
#include "qzregexp.h"
|
||||
#include <QStringList>
|
||||
#include <QWebFrame>
|
||||
#include <QDebug>
|
||||
|
@ -176,7 +176,7 @@ void GM_Script::parseScript()
|
|||
|
||||
QString fileData = QString::fromUtf8(file.readAll());
|
||||
|
||||
QRegExp rx("// ==UserScript==(.*)// ==/UserScript==");
|
||||
QzRegExp rx("// ==UserScript==(.*)// ==/UserScript==");
|
||||
rx.indexIn(fileData);
|
||||
QString metadataBlock = rx.cap(1).trimmed();
|
||||
|
||||
|
|
|
@ -80,22 +80,22 @@ void GM_UrlMatcher::parsePattern(QString pattern)
|
|||
pattern = pattern.mid(1);
|
||||
pattern = pattern.left(pattern.size() - 1);
|
||||
|
||||
m_regExp = QRegExp(pattern, Qt::CaseInsensitive);
|
||||
m_regExp = QzRegExp(pattern, Qt::CaseInsensitive);
|
||||
m_useRegExp = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (pattern.contains(QLatin1String(".tld"))) {
|
||||
|
||||
pattern.replace(QRegExp("(\\W)"), QLatin1String("\\\\1"))
|
||||
.replace(QRegExp("\\*+"), QLatin1String("*"))
|
||||
.replace(QRegExp("^\\\\\\|"), QLatin1String("^"))
|
||||
.replace(QRegExp("\\\\\\|$"), QLatin1String("$"))
|
||||
.replace(QRegExp("\\\\\\*"), QLatin1String(".*"))
|
||||
pattern.replace(QzRegExp("(\\W)"), QLatin1String("\\\\1"))
|
||||
.replace(QzRegExp("\\*+"), QLatin1String("*"))
|
||||
.replace(QzRegExp("^\\\\\\|"), QLatin1String("^"))
|
||||
.replace(QzRegExp("\\\\\\|$"), QLatin1String("$"))
|
||||
.replace(QzRegExp("\\\\\\*"), QLatin1String(".*"))
|
||||
.replace(QLatin1String("\\.tld"), QLatin1String("\\.[a-z.]{2,6}"));
|
||||
|
||||
m_useRegExp = true;
|
||||
m_regExp = QRegExp(pattern, Qt::CaseInsensitive);
|
||||
m_regExp = QzRegExp(pattern, Qt::CaseInsensitive);
|
||||
}
|
||||
else {
|
||||
m_matchString = pattern;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2012-2013 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
|
||||
|
@ -19,7 +19,7 @@
|
|||
#define GM_URLMATCHER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QRegExp>
|
||||
#include "qzregexp.h"
|
||||
|
||||
class GM_UrlMatcher
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ private:
|
|||
QString m_pattern;
|
||||
|
||||
QString m_matchString;
|
||||
QRegExp m_regExp;
|
||||
QzRegExp m_regExp;
|
||||
|
||||
bool m_useRegExp;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user