1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

GreaseMonkey: Use QLatin1String and QLatin1Char in script parsing

This commit is contained in:
nowrep 2012-09-04 11:29:47 +02:00
parent 40a335bc1f
commit 1afc663e91
5 changed files with 34 additions and 31 deletions

View File

@ -287,7 +287,9 @@ bool AdBlockManager::isEnabled()
bool AdBlockManager::canRunOnScheme(const QString &scheme) const
{
return !(scheme == "file" || scheme == "qrc" || scheme == "qupzilla" || scheme == "data" || scheme == "abp");
return !(scheme == QLatin1String("file") || scheme == QLatin1String("qrc")
|| scheme == QLatin1String("qupzilla") || scheme == QLatin1String("data")
|| scheme == QLatin1String("abp"));
}
bool AdBlockManager::canBeBlocked(const QUrl &url) const

View File

@ -237,5 +237,6 @@ void GM_Manager::load()
bool GM_Manager::canRunOnScheme(const QString &scheme)
{
return (scheme == "http" || scheme == "https" || scheme == "data" || scheme == "ftp");
return (scheme == QLatin1String("http") || scheme == QLatin1String("https")
|| scheme == QLatin1String("data") || scheme == QLatin1String("ftp"));
}

View File

@ -38,7 +38,7 @@ PluginSpec GM_Plugin::pluginSpec()
spec.name = "GreaseMonkey";
spec.info = "Userscripts for QupZilla";
spec.description = "Provides support for userscripts (www.userscripts.org)";
spec.version = "0.2.1";
spec.version = "0.2.2";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":gm/data/icon.png");
spec.hasSettings = true;
@ -62,7 +62,7 @@ void GM_Plugin::unload()
bool GM_Plugin::testPlugin()
{
return (QupZilla::VERSION == "1.3.1");
return (QupZilla::VERSION == QLatin1String("1.3.1"));
}
QTranslator* GM_Plugin::getTranslator(const QString &locale)

View File

@ -162,12 +162,12 @@ void GM_Script::parseScript(const QString &filePath)
const QStringList &lines = metadataBlock.split('\n');
foreach(QString line, lines) {
if (!line.startsWith("// @")) {
if (!line.startsWith(QLatin1String("// @"))) {
continue;
}
line = line.mid(3).replace('\t', ' ');
int index = line.indexOf(' ');
line = line.mid(3).replace(QLatin1Char('\t'), QLatin1Char(' '));
int index = line.indexOf(QLatin1Char(' '));
if (index < 0) {
continue;
@ -184,39 +184,39 @@ void GM_Script::parseScript(const QString &filePath)
continue;
}
if (key == "@name") {
if (key == QLatin1String("@name")) {
m_name = value;
}
else if (key == "@namespace") {
else if (key == QLatin1String("@namespace")) {
m_namespace = value;
}
else if (key == "@description") {
else if (key == QLatin1String("@description")) {
m_description = value;
}
else if (key == "@version") {
else if (key == QLatin1String("@version")) {
m_version = value;
}
else if (key == "@updateURL") {
else if (key == QLatin1String("@updateURL")) {
m_downloadUrl = QUrl(value);
}
else if (key == "@include" || key == "@match") {
else if (key == QLatin1String("@include") || key == QLatin1String("@match")) {
m_include.append(GM_UrlMatcher(value));
}
else if (key == "@exclude" || key == "@exclude_match") {
else if (key == QLatin1String("@exclude") || key == QLatin1String("@exclude_match")) {
m_exclude.append(GM_UrlMatcher(value));
}
else if (key == "@require") {
else if (key == QLatin1String("@require")) {
requireList.append(value);
}
else if (key == "@run-at") {
if (value == "document-end") {
else if (key == QLatin1String("@run-at")) {
if (value == QLatin1String("document-end")) {
m_startAt = DocumentEnd;
}
else if (value == "document-start") {
else if (value == QLatin1String("document-start")) {
m_startAt = DocumentStart;
}
}
else if (key == "@downloadURL" && m_downloadUrl.isEmpty()) {
else if (key == QLatin1String("@downloadURL") && m_downloadUrl.isEmpty()) {
m_downloadUrl = QUrl(value);
}
}
@ -225,7 +225,7 @@ void GM_Script::parseScript(const QString &filePath)
m_include.append(GM_UrlMatcher("*"));
}
int index = fileData.indexOf("// ==/UserScript==") + 18;
int index = fileData.indexOf(QLatin1String("// ==/UserScript==")) + 18;
QString script = fileData.mid(index).trimmed();
script.prepend(m_manager->requireScripts(requireList));

View File

@ -25,10 +25,10 @@ bool wildcardMatch(const QString &string, const QString &pattern)
int stringSize = string.size();
int patternSize = pattern.size();
bool startsWithWildcard = pattern[0] == '*';
bool endsWithWildcard = pattern[patternSize - 1] == '*';
bool startsWithWildcard = pattern[0] == QLatin1Char('*');
bool endsWithWildcard = pattern[patternSize - 1] == QLatin1Char('*');
const QStringList &parts = pattern.split('*');
const QStringList &parts = pattern.split(QLatin1Char('*'));
int pos = 0;
if (startsWithWildcard) {
@ -76,7 +76,7 @@ bool GM_UrlMatcher::match(const QString &urlString) const
void GM_UrlMatcher::parsePattern(QString pattern)
{
if (pattern.startsWith('/') && pattern.endsWith('/')) {
if (pattern.startsWith(QLatin1Char('/')) && pattern.endsWith(QLatin1Char('/'))) {
pattern = pattern.mid(1);
pattern = pattern.left(pattern.size() - 1);
@ -85,14 +85,14 @@ void GM_UrlMatcher::parsePattern(QString pattern)
return;
}
if (pattern.contains(".tld")) {
if (pattern.contains(QLatin1String(".tld"))) {
pattern.replace(QRegExp("(\\W)"), "\\\\1")
.replace(QRegExp("\\*+"), "*")
.replace(QRegExp("^\\\\\\|"), "^")
.replace(QRegExp("\\\\\\|$"), "$")
.replace(QRegExp("\\\\\\*"), ".*")
.replace("\\.tld", "\\.[a-z.]{2,6}");
pattern.replace(QRegExp("(\\W)"), QLatin1String("\\\\1"))
.replace(QRegExp("\\*+"), QLatin1String("*"))
.replace(QRegExp("^\\\\\\|"), QLatin1String("^"))
.replace(QRegExp("\\\\\\|$"), QLatin1String("$"))
.replace(QRegExp("\\\\\\*"), QLatin1String(".*"))
.replace("\\.tld", QLatin1String("\\.[a-z.]{2,6}"));
m_useRegExp = true;
m_regExp = QRegExp(pattern, Qt::CaseInsensitive);