Browse Source

Merge pull request #8992 from Chocobo1/regex

Replace QRegExp with QRegularExpression
adaptive-webui-19844
Mike Tzou 7 years ago committed by GitHub
parent
commit
658702dcbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      src/app/upgrade.h
  2. 13
      src/base/bittorrent/magneturi.cpp
  3. 13
      src/base/bittorrent/session.cpp
  4. 1
      src/base/http/connection.cpp
  5. 15
      src/base/net/dnsupdater.cpp
  6. 14
      src/base/preferences.cpp
  7. 5
      src/base/utils/fs.cpp
  8. 8
      src/base/utils/misc.cpp
  9. 21
      src/gui/loglistwidget.cpp
  10. 5
      src/gui/mainwindow.cpp
  11. 27
      src/gui/programupdater.cpp
  12. 7
      src/gui/rss/rsswidget.cpp
  13. 5
      src/gui/search/searchwidget.cpp
  14. 11
      src/gui/transferlistwidget.cpp
  15. 15
      src/webui/webapplication.cpp

39
src/app/upgrade.h

@ -29,34 +29,34 @@
#ifndef UPGRADE_H #ifndef UPGRADE_H
#define UPGRADE_H #define UPGRADE_H
#include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#if LIBTORRENT_VERSION_NUM >= 10100 #if LIBTORRENT_VERSION_NUM >= 10100
#include <libtorrent/bdecode.hpp> #include <libtorrent/bdecode.hpp>
#endif #else
#include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp>
#if LIBTORRENT_VERSION_NUM < 10100
#include <libtorrent/lazy_entry.hpp> #include <libtorrent/lazy_entry.hpp>
#endif #endif
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QRegularExpression>
#include <QString>
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include <QMessageBox> #include <QMessageBox>
#endif #endif
#include <QRegExp>
#include <QString>
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include <QSettings> #include <QSettings>
#endif #endif
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "base/preferences.h"
bool userAcceptsUpgrade() bool userAcceptsUpgrade()
{ {
@ -114,8 +114,9 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent =
bool v3_3 = false; bool v3_3 = false;
int queuePosition = 0; int queuePosition = 0;
QString outFilePath = filepath; QString outFilePath = filepath;
QRegExp rx(QLatin1String("([A-Fa-f0-9]{40})\\.fastresume\\.(.+)$")); static const QRegularExpression rx(QLatin1String("([A-Fa-f0-9]{40})\\.fastresume\\.(.+)$"));
if (rx.indexIn(filepath) != -1) { const QRegularExpressionMatch rxMatch = rx.match(filepath);
if (rxMatch.hasMatch()) {
// Old v3.3.x format had a number at the end indicating the queue position. // Old v3.3.x format had a number at the end indicating the queue position.
// The naming scheme was '<infohash>.fastresume.<queueposition>'. // The naming scheme was '<infohash>.fastresume.<queueposition>'.
// However, QSaveFile, which uses QTemporaryFile internally, might leave // However, QSaveFile, which uses QTemporaryFile internally, might leave
@ -127,14 +128,14 @@ bool upgradeResumeFile(const QString &filepath, const QVariantHash &oldTorrent =
// and is deleted, because it may be a corrupted/incomplete fastresume. // and is deleted, because it may be a corrupted/incomplete fastresume.
// NOTE: When the upgrade code is removed, we must continue to perform // NOTE: When the upgrade code is removed, we must continue to perform
// cleanup of non-commited QSaveFile/QTemporaryFile fastresumes // cleanup of non-commited QSaveFile/QTemporaryFile fastresumes
queuePosition = rx.cap(2).toInt(); queuePosition = rxMatch.captured(2).toInt();
if ((rx.cap(2).size() == 6) && (queuePosition <= 99999)) { if ((rxMatch.captured(2).size() == 6) && (queuePosition <= 99999)) {
Utils::Fs::forceRemove(filepath); Utils::Fs::forceRemove(filepath);
return true; return true;
} }
v3_3 = true; v3_3 = true;
outFilePath.replace(QRegExp("\\.fastresume\\..+$"), ".fastresume"); outFilePath.replace(QRegularExpression("\\.fastresume\\..+$"), ".fastresume");
} }
else { else {
queuePosition = fastOld.dict_find_int_value("qBt-queuePosition", 0); queuePosition = fastOld.dict_find_int_value("qBt-queuePosition", 0);
@ -198,13 +199,15 @@ bool upgrade(bool ask = true)
QStringList backupFiles = backupFolderDir.entryList( QStringList backupFiles = backupFolderDir.entryList(
QStringList(QLatin1String("*.fastresume")), QDir::Files, QDir::Unsorted); QStringList(QLatin1String("*.fastresume")), QDir::Files, QDir::Unsorted);
QRegExp rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$")); const QRegularExpression rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$"));
foreach (QString backupFile, backupFiles) { foreach (QString backupFile, backupFiles) {
if (rx.indexIn(backupFile) != -1) { const QRegularExpressionMatch rxMatch = rx.match(backupFile);
if (upgradeResumeFile(backupFolderDir.absoluteFilePath(backupFile), oldResumeData[rx.cap(1)].toHash())) if (rxMatch.hasMatch()) {
oldResumeData.remove(rx.cap(1)); const QString hashStr = rxMatch.captured(1);
if (upgradeResumeFile(backupFolderDir.absoluteFilePath(backupFile), oldResumeData[hashStr].toHash()))
oldResumeData.remove(hashStr);
else else
Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent with hash: %1").arg(rx.cap(1)), Log::WARNING); Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent with hash: %1").arg(hashStr), Log::WARNING);
} }
else { else {
Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent. Invalid fastresume file name: %1").arg(backupFile), Log::WARNING); Logger::instance()->addMessage(QObject::tr("Couldn't migrate torrent. Invalid fastresume file name: %1").arg(backupFile), Log::WARNING);

13
src/base/bittorrent/magneturi.cpp

@ -26,16 +26,17 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include <QByteArray> #include "magneturi.h"
#include <QRegExp>
#include <QStringList>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/error_code.hpp> #include <libtorrent/error_code.hpp>
#include <libtorrent/magnet_uri.hpp> #include <libtorrent/magnet_uri.hpp>
#include <QByteArray>
#include <QRegularExpression>
#include <QStringList>
#include "base/utils/string.h" #include "base/utils/string.h"
#include "magneturi.h"
namespace namespace
{ {
@ -69,8 +70,8 @@ MagnetUri::MagnetUri(const QString &source)
qDebug("Creating magnet link from bc link"); qDebug("Creating magnet link from bc link");
m_url = bcLinkToMagnet(source); m_url = bcLinkToMagnet(source);
} }
else if (((source.size() == 40) && !source.contains(QRegExp("[^0-9A-Fa-f]"))) else if (((source.size() == 40) && !source.contains(QRegularExpression("[^0-9A-Fa-f]")))
|| ((source.size() == 32) && !source.contains(QRegExp("[^2-7A-Za-z]")))) { || ((source.size() == 32) && !source.contains(QRegularExpression("[^2-7A-Za-z]")))) {
m_url = "magnet:?xt=urn:btih:" + source; m_url = "magnet:?xt=urn:btih:" + source;
} }

13
src/base/bittorrent/session.cpp

@ -42,7 +42,7 @@
#include <QNetworkAddressEntry> #include <QNetworkAddressEntry>
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QProcess> #include <QProcess>
#include <QRegExp> #include <QRegularExpression>
#include <QString> #include <QString>
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
@ -692,8 +692,8 @@ QString Session::torrentTempPath(const TorrentInfo &torrentInfo) const
bool Session::isValidCategoryName(const QString &name) bool Session::isValidCategoryName(const QString &name)
{ {
QRegExp re(R"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"); static const QRegularExpression re(R"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)");
if (!name.isEmpty() && (re.indexIn(name) != 0)) { if (!name.isEmpty() && (name.indexOf(re) != 0)) {
qDebug() << "Incorrect category name:" << name; qDebug() << "Incorrect category name:" << name;
return false; return false;
} }
@ -3829,11 +3829,12 @@ void Session::startUpTorrents()
QMap<int, TorrentResumeData> queuedResumeData; QMap<int, TorrentResumeData> queuedResumeData;
int nextQueuePosition = 1; int nextQueuePosition = 1;
int numOfRemappedFiles = 0; int numOfRemappedFiles = 0;
QRegExp rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$")); const QRegularExpression rx(QLatin1String("^([A-Fa-f0-9]{40})\\.fastresume$"));
foreach (const QString &fastresumeName, fastresumes) { foreach (const QString &fastresumeName, fastresumes) {
if (rx.indexIn(fastresumeName) == -1) continue; const QRegularExpressionMatch rxMatch = rx.match(fastresumeName);
if (!rxMatch.hasMatch()) continue;
QString hash = rx.cap(1); QString hash = rxMatch.captured(1);
QString fastresumePath = resumeDataDir.absoluteFilePath(fastresumeName); QString fastresumePath = resumeDataDir.absoluteFilePath(fastresumeName);
QByteArray data; QByteArray data;
AddTorrentData resumeData; AddTorrentData resumeData;

1
src/base/http/connection.cpp

@ -30,7 +30,6 @@
#include "connection.h" #include "connection.h"
#include <QRegExp>
#include <QTcpSocket> #include <QTcpSocket>
#include "base/logger.h" #include "base/logger.h"

15
src/base/net/dnsupdater.cpp

@ -26,15 +26,16 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "dnsupdater.h"
#include <QDebug> #include <QDebug>
#include <QRegExp> #include <QRegularExpression>
#include <QStringList> #include <QStringList>
#include <QUrlQuery> #include <QUrlQuery>
#include "base/logger.h" #include "base/logger.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "dnsupdater.h"
using namespace Net; using namespace Net;
@ -89,9 +90,9 @@ void DNSUpdater::ipRequestFinished(const QString &url, const QByteArray &data)
Q_UNUSED(url); Q_UNUSED(url);
// Parse response // Parse response
QRegExp ipregex("Current IP Address:\\s+([^<]+)</body>"); const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(data);
if (ipregex.indexIn(data) >= 0) { if (ipRegexMatch.hasMatch()) {
QString ipStr = ipregex.cap(1); QString ipStr = ipRegexMatch.captured(1);
qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr; qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr;
QHostAddress newIp(ipStr); QHostAddress newIp(ipStr);
if (!newIp.isNull()) { if (!newIp.isNull()) {
@ -246,8 +247,8 @@ void DNSUpdater::updateCredentials()
} }
if (m_domain != pref->getDynDomainName()) { if (m_domain != pref->getDynDomainName()) {
m_domain = pref->getDynDomainName(); m_domain = pref->getDynDomainName();
QRegExp domain_regex("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$"); const QRegularExpressionMatch domainRegexMatch = QRegularExpression("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$").match(m_domain);
if (domain_regex.indexIn(m_domain) < 0) { if (!domainRegexMatch.hasMatch()) {
logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL); logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL);
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();

14
src/base/preferences.cpp

@ -45,6 +45,7 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <shlobj.h> #include <shlobj.h>
#include <winreg.h> #include <winreg.h>
#include <QRegularExpression>
#endif #endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -1021,13 +1022,14 @@ bool Preferences::isMagnetLinkAssocSet()
QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat); QSettings settings("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat);
// Check magnet link assoc // Check magnet link assoc
QRegExp exe_reg("\"([^\"]+)\".*"); const QString shellCommand = Utils::Fs::toNativePath(settings.value("magnet/shell/open/command/Default", "").toString());
QString shell_command = Utils::Fs::toNativePath(settings.value("magnet/shell/open/command/Default", "").toString());
if (exe_reg.indexIn(shell_command) < 0) const QRegularExpressionMatch exeRegMatch = QRegularExpression("\"([^\"]+)\".*").match(shellCommand);
if (!exeRegMatch.hasMatch())
return false; return false;
QString assoc_exe = exe_reg.cap(1);
qDebug("exe: %s", qUtf8Printable(assoc_exe)); const QString assocExe = exeRegMatch.captured(1);
if (assoc_exe.compare(Utils::Fs::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0) if (assocExe.compare(Utils::Fs::toNativePath(qApp->applicationFilePath()), Qt::CaseInsensitive) != 0)
return false; return false;
return true; return true;

5
src/base/utils/fs.cpp

@ -37,6 +37,7 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QStorageInfo> #include <QStorageInfo>
#include <QRegularExpression>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -218,7 +219,7 @@ bool Utils::Fs::sameFiles(const QString &path1, const QString &path2)
QString Utils::Fs::toValidFileSystemName(const QString &name, bool allowSeparators, const QString &pad) QString Utils::Fs::toValidFileSystemName(const QString &name, bool allowSeparators, const QString &pad)
{ {
QRegExp regex(allowSeparators ? "[:?\"*<>|]+" : "[\\\\/:?\"*<>|]+"); const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]+" : "[\\\\/:?\"*<>|]+");
QString validName = name.trimmed(); QString validName = name.trimmed();
validName.replace(regex, pad); validName.replace(regex, pad);
@ -231,7 +232,7 @@ bool Utils::Fs::isValidFileSystemName(const QString &name, bool allowSeparators)
{ {
if (name.isEmpty()) return false; if (name.isEmpty()) return false;
QRegExp regex(allowSeparators ? "[:?\"*<>|]" : "[\\\\/:?\"*<>|]"); const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]" : "[\\\\/:?\"*<>|]");
return !name.contains(regex); return !name.contains(regex);
} }

8
src/base/utils/misc.cpp

@ -50,7 +50,6 @@
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QProcess> #include <QProcess>
#include <QRegExp>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSysInfo> #include <QSysInfo>
#include <QUrl> #include <QUrl>
@ -529,7 +528,7 @@ bool Utils::Misc::isUrl(const QString &s)
QString Utils::Misc::parseHtmlLinks(const QString &rawText) QString Utils::Misc::parseHtmlLinks(const QString &rawText)
{ {
QString result = rawText; QString result = rawText;
static QRegExp reURL( static const QRegularExpression reURL(
"(\\s|^)" // start with whitespace or beginning of line "(\\s|^)" // start with whitespace or beginning of line
"(" "("
"(" // case 1 -- URL with scheme "(" // case 1 -- URL with scheme
@ -576,12 +575,11 @@ QString Utils::Misc::parseHtmlLinks(const QString &rawText)
")" ")"
); );
// Capture links // Capture links
result.replace(reURL, "\\1<a href=\"\\2\">\\2</a>"); result.replace(reURL, "\\1<a href=\"\\2\">\\2</a>");
// Capture links without scheme // Capture links without scheme
static QRegExp reNoScheme("<a\\s+href=\"(?!http(s?))([a-zA-Z0-9\\?%=&/_\\.-:#]+)\\s*\">"); static const QRegularExpression reNoScheme("<a\\s+href=\"(?!https?)([a-zA-Z0-9\\?%=&/_\\.-:#]+)\\s*\">");
result.replace(reNoScheme, "<a href=\"http://\\1\">"); result.replace(reNoScheme, "<a href=\"http://\\1\">");
// to preserve plain text formatting // to preserve plain text formatting
@ -632,7 +630,7 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath)
|| (output == "nautilus-folder-handler.desktop")) { || (output == "nautilus-folder-handler.desktop")) {
proc.start("nautilus", {"--version"}); proc.start("nautilus", {"--version"});
proc.waitForFinished(); proc.waitForFinished();
const QString nautilusVerStr = QString(proc.readLine()).remove(QRegExp("[^0-9.]")); const QString nautilusVerStr = QString(proc.readLine()).remove(QRegularExpression("[^0-9.]"));
using NautilusVersion = Utils::Version<int, 3>; using NautilusVersion = Utils::Version<int, 3>;
if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28}) if (NautilusVersion::tryParse(nautilusVerStr, {1, 0, 0}) > NautilusVersion {3, 28})
proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)}); proc.startDetached("nautilus", {Utils::Fs::toNativePath(path)});

21
src/gui/loglistwidget.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,17 +24,18 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include <QKeyEvent>
#include "loglistwidget.h"
#include <QAction>
#include <QApplication> #include <QApplication>
#include <QClipboard> #include <QClipboard>
#include <QListWidgetItem> #include <QKeyEvent>
#include <QLabel> #include <QLabel>
#include <QRegExp> #include <QListWidgetItem>
#include <QAction> #include <QRegularExpression>
#include "loglistwidget.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
LogListWidget::LogListWidget(int maxLines, const Log::MsgTypes &types, QWidget *parent) LogListWidget::LogListWidget(int maxLines, const Log::MsgTypes &types, QWidget *parent)
@ -94,10 +95,10 @@ void LogListWidget::appendLine(const QString &line, const Log::MsgType &type)
void LogListWidget::copySelection() void LogListWidget::copySelection()
{ {
static QRegExp htmlTag("<[^>]+>"); static const QRegularExpression htmlTag("<[^>]+>");
QStringList strings; QStringList strings;
foreach (QListWidgetItem* it, selectedItems()) foreach (QListWidgetItem* it, selectedItems())
strings << static_cast<QLabel*>(itemWidget(it))->text().replace(htmlTag, ""); strings << static_cast<QLabel*>(itemWidget(it))->text().remove(htmlTag);
QApplication::clipboard()->setText(strings.join("\n")); QApplication::clipboard()->setText(strings.join("\n"));
} }

5
src/gui/mainwindow.cpp

@ -41,6 +41,7 @@
#include <QMimeData> #include <QMimeData>
#include <QProcess> #include <QProcess>
#include <QPushButton> #include <QPushButton>
#include <QRegularExpression>
#include <QScrollBar> #include <QScrollBar>
#include <QShortcut> #include <QShortcut>
#include <QSplitter> #include <QSplitter>
@ -1599,8 +1600,8 @@ void MainWindow::downloadFromURLList(const QStringList &urlList)
{ {
const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled(); const bool useTorrentAdditionDialog = AddNewTorrentDialog::isEnabled();
foreach (QString url, urlList) { foreach (QString url, urlList) {
if (((url.size() == 40) && !url.contains(QRegExp("[^0-9A-Fa-f]"))) if (((url.size() == 40) && !url.contains(QRegularExpression("[^0-9A-Fa-f]")))
|| ((url.size() == 32) && !url.contains(QRegExp("[^2-7A-Za-z]")))) || ((url.size() == 32) && !url.contains(QRegularExpression("[^2-7A-Za-z]"))))
url = "magnet:?xt=urn:btih:" + url; url = "magnet:?xt=urn:btih:" + url;
if (useTorrentAdditionDialog) if (useTorrentAdditionDialog)

27
src/gui/programupdater.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2010 Christophe Dumez * Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,20 +24,19 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include <QXmlStreamReader> #include "programupdater.h"
#include <QDesktopServices>
#include <QDebug> #include <QDebug>
#include <QRegExp> #include <QDesktopServices>
#include <QRegularExpression>
#include <QStringList> #include <QStringList>
#include <QXmlStreamReader>
#include "base/utils/fs.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "programupdater.h" #include "base/net/downloadmanager.h"
#include "base/utils/fs.h"
namespace namespace
{ {
@ -137,9 +136,9 @@ void ProgramUpdater::updateProgram()
bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
{ {
QRegExp regVer("([0-9.]+)"); const QRegularExpressionMatch regVerMatch = QRegularExpression("([0-9.]+)").match(QBT_VERSION);
if (regVer.indexIn(QBT_VERSION) >= 0) { if (regVerMatch.hasMatch()) {
QString localVersion = regVer.cap(1); QString localVersion = regVerMatch.captured(1);
qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << QBT_VERSION; qDebug() << Q_FUNC_INFO << "local version:" << localVersion << "/" << QBT_VERSION;
QStringList remoteParts = remoteVersion.split('.'); QStringList remoteParts = remoteVersion.split('.');
QStringList localParts = localVersion.split('.'); QStringList localParts = localVersion.split('.');
@ -153,8 +152,8 @@ bool ProgramUpdater::isVersionMoreRecent(const QString &remoteVersion) const
if (remoteParts.size() > localParts.size()) if (remoteParts.size() > localParts.size())
return true; return true;
// versions are equal, check if the local version is a development release, in which case it is older (2.9.2beta < 2.9.2) // versions are equal, check if the local version is a development release, in which case it is older (2.9.2beta < 2.9.2)
QRegExp regDevel("(alpha|beta|rc)"); const QRegularExpressionMatch regDevelMatch = QRegularExpression("(alpha|beta|rc)").match(QBT_VERSION);
if (regDevel.indexIn(QBT_VERSION) >= 0) if (regDevelMatch.hasMatch())
return true; return true;
} }
return false; return false;

7
src/gui/rss/rsswidget.cpp

@ -36,6 +36,7 @@
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QRegularExpression>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QString> #include <QString>
@ -461,10 +462,10 @@ void RSSWidget::handleCurrentArticleItemChanged(QListWidgetItem *currentItem, QL
} }
else { else {
QString description = article->description(); QString description = article->description();
QRegExp rx; QRegularExpression rx;
// If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice // If description is plain text, replace BBCode tags with HTML and wrap everything in <pre></pre> so it looks nice
rx.setMinimal(true); rx.setPatternOptions(QRegularExpression::InvertedGreedinessOption
rx.setCaseSensitivity(Qt::CaseInsensitive); | QRegularExpression::CaseInsensitiveOption);
rx.setPattern("\\[img\\](.+)\\[/img\\]"); rx.setPattern("\\[img\\](.+)\\[/img\\]");
description = description.replace(rx, "<img src=\"\\1\">"); description = description.replace(rx, "<img src=\"\\1\">");

5
src/gui/search/searchwidget.cpp

@ -29,6 +29,8 @@
#include "searchwidget.h" #include "searchwidget.h"
#include <QtGlobal>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <cstdlib> #include <cstdlib>
#endif #endif
@ -41,6 +43,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QMimeData> #include <QMimeData>
#include <QProcess> #include <QProcess>
#include <QRegularExpression>
#include <QSignalMapper> #include <QSignalMapper>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStandardItemModel> #include <QStandardItemModel>
@ -320,7 +323,7 @@ void SearchWidget::on_searchButton_clicked()
m_allTabs.append(newTab); m_allTabs.append(newTab);
QString tabName = pattern; QString tabName = pattern;
tabName.replace(QRegExp("&{1}"), "&&"); tabName.replace(QRegularExpression("&{1}"), "&&");
m_ui->tabWidget->addTab(newTab, tabName); m_ui->tabWidget->addTab(newTab, tabName);
m_ui->tabWidget->setCurrentWidget(newTab); m_ui->tabWidget->setCurrentWidget(newTab);

11
src/gui/transferlistwidget.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "transferlistwidget.h" #include "transferlistwidget.h"
@ -35,14 +33,14 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QStylePainter>
#include <QRegExp> #include <QRegExp>
#include <QRegularExpression>
#include <QShortcut> #include <QShortcut>
#include <QStylePainter>
#include <QTableView> #include <QTableView>
#include <QWheelEvent> #include <QWheelEvent>
#include <QWidgetAction> #include <QWidgetAction>
#include "autoexpandabledialog.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/logger.h" #include "base/logger.h"
@ -50,6 +48,7 @@
#include "base/torrentfilter.h" #include "base/torrentfilter.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "autoexpandabledialog.h"
#include "deletionconfirmationdlg.h" #include "deletionconfirmationdlg.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "mainwindow.h" #include "mainwindow.h"
@ -832,7 +831,7 @@ void TransferListWidget::renameSelectedTorrent()
bool ok; bool ok;
QString name = AutoExpandableDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, torrent->name(), &ok); QString name = AutoExpandableDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, torrent->name(), &ok);
if (ok && !name.isEmpty()) { if (ok && !name.isEmpty()) {
name.replace(QRegExp("\r?\n|\r"), " "); name.replace(QRegularExpression("\r?\n|\r"), " ");
// Rename the torrent // Rename the torrent
m_listModel->setData(mi, name, Qt::DisplayRole); m_listModel->setData(mi, name, Qt::DisplayRole);
} }

15
src/webui/webapplication.cpp

@ -97,8 +97,8 @@ namespace
void translateDocument(const QString &locale, QString &data) void translateDocument(const QString &locale, QString &data)
{ {
const QRegExp regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])"); const QRegularExpression regex("QBT_TR\\((([^\\)]|\\)(?!QBT_TR))+)\\)QBT_TR(\\[CONTEXT=([a-zA-Z_][a-zA-Z0-9_]*)\\])");
const QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?"); const QRegularExpression mnemonic("\\(?&([a-zA-Z]?\\))?");
const bool isTranslationNeeded = !locale.startsWith("en") const bool isTranslationNeeded = !locale.startsWith("en")
|| locale.startsWith("en_AU") || locale.startsWith("en_GB"); || locale.startsWith("en_AU") || locale.startsWith("en_GB");
@ -106,23 +106,24 @@ namespace
int i = 0; int i = 0;
bool found = true; bool found = true;
while (i < data.size() && found) { while (i < data.size() && found) {
i = regex.indexIn(data, i); QRegularExpressionMatch regexMatch;
i = data.indexOf(regex, i, &regexMatch);
if (i >= 0) { if (i >= 0) {
const QString word = regex.cap(1); const QString word = regexMatch.captured(1);
const QString context = regex.cap(4); const QString context = regexMatch.captured(4);
QString translation = isTranslationNeeded QString translation = isTranslationNeeded
? qApp->translate(context.toUtf8().constData(), word.toUtf8().constData(), nullptr, 1) ? qApp->translate(context.toUtf8().constData(), word.toUtf8().constData(), nullptr, 1)
: word; : word;
// Remove keyboard shortcuts // Remove keyboard shortcuts
translation.replace(mnemonic, ""); translation.remove(mnemonic);
// Use HTML code for quotes to prevent issues with JS // Use HTML code for quotes to prevent issues with JS
translation.replace('\'', "&#39;"); translation.replace('\'', "&#39;");
translation.replace('\"', "&#34;"); translation.replace('\"', "&#34;");
data.replace(i, regex.matchedLength(), translation); data.replace(i, regexMatch.capturedLength(), translation);
i += translation.length(); i += translation.length();
} }
else { else {

Loading…
Cancel
Save