From 8582c2ad5708a1972c85bea1cf8d81ad3ece4814 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 9 Sep 2018 23:37:56 +0200 Subject: [PATCH] modernize: Use raw string literals instead of escaped strings Replace escaped strings with raw string literals in places where it makes sense, and doesn't confuse lupdate. --- src/client/clientuserinputhandler.cpp | 2 +- src/client/execwrapper.cpp | 4 +-- src/common/aliasmanager.cpp | 2 +- src/common/identity.cpp | 2 +- src/core/coresession.cpp | 2 +- src/core/coreuserinputhandler.cpp | 2 +- src/core/ctcpparser.cpp | 2 +- src/core/ircparser.cpp | 2 +- src/core/netsplit.cpp | 2 +- src/core/oidentdconfiggenerator.cpp | 2 +- src/qtui/chatscene.cpp | 2 +- src/qtui/qtuistyle.cpp | 2 +- .../settingspages/identitiessettingspage.cpp | 2 +- src/uisupport/clickable.cpp | 8 +++--- src/uisupport/contextmenuactionprovider.cpp | 2 +- src/uisupport/qssparser.cpp | 28 +++++++++---------- src/uisupport/tabcompleter.cpp | 4 +-- 17 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/client/clientuserinputhandler.cpp b/src/client/clientuserinputhandler.cpp index 573a28ab..7179515a 100644 --- a/src/client/clientuserinputhandler.cpp +++ b/src/client/clientuserinputhandler.cpp @@ -50,7 +50,7 @@ void ClientUserInputHandler::completionSuffixChanged(const QVariant &v) { QString suffix = v.toString(); QString letter = "A-Za-z"; - QString special = "\x5b-\x60\x7b-\x7d"; + QString special = "\x5b-\x60\x7b-\x7d"; // NOLINT(modernize-raw-string-literal) _nickRx = QRegExp(QString("^([%1%2][%1%2\\d-]*)%3").arg(letter, special, suffix).trimmed()); } diff --git a/src/client/execwrapper.cpp b/src/client/execwrapper.cpp index 28bffeae..85125830 100644 --- a/src/client/execwrapper.cpp +++ b/src/client/execwrapper.cpp @@ -44,7 +44,7 @@ void ExecWrapper::start(const BufferInfo &info, const QString &command) _bufferInfo = info; QString params; - QRegExp rx("^\\s*(\\S+)(\\s+(.*))?$"); + QRegExp rx(R"(^\s*(\S+)(\s+(.*))?$)"); if (!rx.exactMatch(command)) { emit error(tr("Invalid command string for /exec: %1").arg(command)); } @@ -55,7 +55,7 @@ void ExecWrapper::start(const BufferInfo &info, const QString &command) // Make sure we don't execute something outside a script dir if (_scriptName.contains("../") || _scriptName.contains("..\\")) - emit error(tr("Name \"%1\" is invalid: ../ or ..\\ are not allowed!").arg(_scriptName)); + emit error(tr(R"(Name "%1" is invalid: ../ or ..\ are not allowed!)").arg(_scriptName)); else { foreach(QString scriptDir, Quassel::scriptDirPaths()) { diff --git a/src/common/aliasmanager.cpp b/src/common/aliasmanager.cpp index efb148f6..356cd324 100644 --- a/src/common/aliasmanager.cpp +++ b/src/common/aliasmanager.cpp @@ -160,7 +160,7 @@ void AliasManager::expand(const QString &alias, const BufferInfo &bufferInfo, co return; } - QRegExp paramRangeR("\\$(\\d+)\\.\\.(\\d*)"); + QRegExp paramRangeR(R"(\$(\d+)\.\.(\d*))"); QStringList commands = alias.split(QRegExp("; ?")); QStringList params = msg.split(' '); QStringList expandedCommands; diff --git a/src/common/identity.cpp b/src/common/identity.cpp index e2cd936b..9d885e0e 100644 --- a/src/common/identity.cpp +++ b/src/common/identity.cpp @@ -135,7 +135,7 @@ QString Identity::defaultNick() #endif // cleaning forbidden characters from nick - QRegExp rx(QString("(^[\\d-]+|[^A-Za-z0-9\x5b-\x60\x7b-\x7d])")); + QRegExp rx(QString("(^[\\d-]+|[^A-Za-z0-9\x5b-\x60\x7b-\x7d])")); // NOLINT(modernize-raw-string-literal) nick.remove(rx); return nick; } diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index ab4859b2..f2e96710 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -609,7 +609,7 @@ void CoreSession::createNetwork(const NetworkInfo &info_, const QStringList &per id = info.networkId.toInt(); if (!_networks.contains(id)) { // create persistent chans - QRegExp rx("\\s*(\\S+)(?:\\s*(\\S+))?\\s*"); + QRegExp rx(R"(\s*(\S+)(?:\s*(\S+))?\s*)"); foreach(QString channel, persistentChans) { if (!rx.exactMatch(channel)) { qWarning() << QString("Invalid persistent channel declaration: %1").arg(channel); diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index d060ada2..0b3b2b0a 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -144,7 +144,7 @@ void CoreUserInputHandler::banOrUnban(const BufferInfo &bufferInfo, const QStrin return; } - static QRegExp ipAddress("\\d+\\.\\d+\\.\\d+\\.\\d+"); + static QRegExp ipAddress(R"(\d+\.\d+\.\d+\.\d+)"); if (ipAddress.exactMatch(generalizedHost)) { int lastDotPos = generalizedHost.lastIndexOf('.') + 1; generalizedHost.replace(lastDotPos, generalizedHost.length() - lastDotPos, '*'); diff --git a/src/core/ctcpparser.cpp b/src/core/ctcpparser.cpp index d58d28d0..8c43ffb3 100644 --- a/src/core/ctcpparser.cpp +++ b/src/core/ctcpparser.cpp @@ -47,7 +47,7 @@ CtcpParser::CtcpParser(CoreSession *coreSession, QObject *parent) void CtcpParser::setStandardCtcp(bool enabled) { - QByteArray XQUOTE = QByteArray("\134"); + QByteArray XQUOTE = QByteArray(R"(\)"); if (enabled) _ctcpXDelimDequoteHash[XQUOTE + XQUOTE] = XQUOTE; else diff --git a/src/core/ircparser.cpp b/src/core/ircparser.cpp index 5c6fce76..4ffcc5d3 100644 --- a/src/core/ircparser.cpp +++ b/src/core/ircparser.cpp @@ -239,7 +239,7 @@ void IrcParser::processNetworkIncoming(NetworkDataEvent *e) // :ChanServ!ChanServ@services. NOTICE egst :[#apache] Welcome, this is #apache. Please read the in-channel topic message. This channel is being logged by IRSeekBot. If you have any question please see http://blog.freenode.net/?p=68 if (!net->isChannelName(target)) { QString decMsg = net->serverDecode(params.at(1)); - QRegExp welcomeRegExp("^\\[([^\\]]+)\\] "); + QRegExp welcomeRegExp(R"(^\[([^\]]+)\] )"); if (welcomeRegExp.indexIn(decMsg) != -1) { QString channelname = welcomeRegExp.cap(1); decMsg = decMsg.mid(welcomeRegExp.matchedLength()); diff --git a/src/core/netsplit.cpp b/src/core/netsplit.cpp index 04ab70be..b44c39d4 100644 --- a/src/core/netsplit.cpp +++ b/src/core/netsplit.cpp @@ -117,7 +117,7 @@ bool Netsplit::isNetsplit(const QString &quitMessage) // now test if message consists only of two dns names as the RFC requests // but also allow the commonly used "*.net *.split" - QRegExp hostRx("^(?:[\\w\\d-.]+|\\*)\\.[\\w\\d-]+\\s(?:[\\w\\d-.]+|\\*)\\.[\\w\\d-]+$"); + QRegExp hostRx(R"(^(?:[\w\d-.]+|\*)\.[\w\d-]+\s(?:[\w\d-.]+|\*)\.[\w\d-]+$)"); if (hostRx.exactMatch(quitMessage)) return true; diff --git a/src/core/oidentdconfiggenerator.cpp b/src/core/oidentdconfiggenerator.cpp index 08b7636c..7e758710 100644 --- a/src/core/oidentdconfiggenerator.cpp +++ b/src/core/oidentdconfiggenerator.cpp @@ -63,7 +63,7 @@ bool OidentdConfigGenerator::init() // the ability to bind to an IP on client sockets. _quasselStanzaTemplate = QString("lport %1 { reply \"%2\" } #%3\n"); - _quasselStanzaRx = QRegExp(QString("^lport .* \\{ .* \\} #%1\\r?\\n").arg(_configTag)); + _quasselStanzaRx = QRegExp(QString(R"(^lport .* \{ .* \} #%1\r?\n)").arg(_configTag)); // initially remove all Quassel stanzas that might be present if (parseConfig(false) && writeConfig()) diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 70c3b649..b2b1a35e 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -1392,7 +1392,7 @@ void ChatScene::updateTimestampHasBrackets() // (^\s*\(.+\)\s*$)|(^\s*\{.+\}\s*$)|(^\s*\[.+\]\s*$)|(^\s*<.+>\s*$) // Note that '\' must be escaped as '\\' // Helpful interactive website for debugging and explaining: https://regex101.com/ - const QRegExp regExpMatchBrackets("^\\s*[({[<].+[)}\\]>]\\s*$"); + const QRegExp regExpMatchBrackets(R"(^\s*[({[<].+[)}\]>]\s*$)"); _timestampHasBrackets = regExpMatchBrackets.exactMatch(_timestampFormatString); } } diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index fd10e24a..efca13a5 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -198,7 +198,7 @@ void QtUiStyle::generateSettingsQss() const out << "\n// NickView Colors\n" << "NickListItem[type=\"category\"] { foreground: " << color("DefaultBuffer", uiColors) << "; }\n" << "NickListItem[type=\"user\"] { foreground: " << color("OnlineNick", uiColors) << "; }\n" - << "NickListItem[type=\"user\", state=\"away\"] { foreground: " << color("AwayNick", uiColors) << "; }\n"; + << R"(NickListItem[type="user", state="away"] { foreground: )" << color("AwayNick", uiColors) << "; }\n"; } settingsQss.close(); diff --git a/src/qtui/settingspages/identitiessettingspage.cpp b/src/qtui/settingspages/identitiessettingspage.cpp index e2d94f10..0cf99742 100644 --- a/src/qtui/settingspages/identitiessettingspage.cpp +++ b/src/qtui/settingspages/identitiessettingspage.cpp @@ -472,7 +472,7 @@ NickEditDlg::NickEditDlg(const QString &old, QStringList exist, QWidget *parent) // define a regexp for valid nicknames // TODO: add max nicklength according to ISUPPORT QString letter = "A-Za-z"; - QString special = "\x5b-\x60\x7b-\x7d"; + QString special = R"([-`{-})"; QRegExp rx(QString("[%1%2][%1%2\\d-]*").arg(letter, special)); ui.nickEdit->setValidator(new QRegExpValidator(rx, ui.nickEdit)); if (old.isEmpty()) { diff --git a/src/uisupport/clickable.cpp b/src/uisupport/clickable.cpp index 1f5720ef..851e1caa 100644 --- a/src/uisupport/clickable.cpp +++ b/src/uisupport/clickable.cpp @@ -53,10 +53,10 @@ void Clickable::activate(NetworkId networkId, const QString &text) const ClickableList ClickableList::fromString(const QString &str) { // For matching URLs - static QString scheme("(?:(?:mailto:|(?:[+.-]?\\w)+://)|www(?=\\.\\S+\\.))"); - static QString authority("(?:(?:[,.;@:]?[-\\w]+)+\\.?|\\[[0-9a-f:.]+\\])(?::\\d+)?"); + static QString scheme(R"((?:(?:mailto:|(?:[+.-]?\w)+://)|www(?=\.\S+\.)))"); + static QString authority(R"((?:(?:[,.;@:]?[-\w]+)+\.?|\[[0-9a-f:.]+\])(?::\d+)?)"); static QString urlChars("(?:[,.;:]*[\\w~@/?&=+$()!%#*-])"); - static QString urlEnd("(?:>|[,.;:\"]*\\s|\\b|$)"); + static QString urlEnd("(?:>|[,.;:\"]*\\s|\\b|$)"); // NOLINT(modernize-raw-string-literal) static QRegExp regExp[] = { // URL @@ -65,7 +65,7 @@ ClickableList ClickableList::fromString(const QString &str) // Channel name // We don't match for channel names starting with + or &, because that gives us a lot of false positives. - QRegExp("((?:#|![A-Z0-9]{5})[^,:\\s]+(?::[^,:\\s]+)?)\\b", Qt::CaseInsensitive) + QRegExp(R"(((?:#|![A-Z0-9]{5})[^,:\s]+(?::[^,:\s]+)?)\b)", Qt::CaseInsensitive) // TODO: Nicks, we'll need a filtering for only matching known nicknames further down if we do this }; diff --git a/src/uisupport/contextmenuactionprovider.cpp b/src/uisupport/contextmenuactionprovider.cpp index 79c9d19b..3bc7cd07 100644 --- a/src/uisupport/contextmenuactionprovider.cpp +++ b/src/uisupport/contextmenuactionprovider.cpp @@ -458,7 +458,7 @@ void ContextMenuActionProvider::addIgnoreMenu(QMenu *menu, const QString &hostma QString ident = userFromMask(hostmask); QString host = hostFromMask(hostmask); QString domain = host; - QRegExp domainRx = QRegExp("(\\.[^.]+\\.\\w+\\D)$"); + QRegExp domainRx = QRegExp(R"((\.[^.]+\.\w+\D)$)"); if (domainRx.indexIn(host) != -1) domain = domainRx.cap(1); // we can't rely on who-data diff --git a/src/uisupport/qssparser.cpp b/src/uisupport/qssparser.cpp index 61679d95..495adc5c 100644 --- a/src/uisupport/qssparser.cpp +++ b/src/uisupport/qssparser.cpp @@ -82,7 +82,7 @@ void QssParser::processStyleSheet(QString &ss) return; // Remove C-style comments /* */ or // - static QRegExp commentRx("(//.*(\\n|$)|/\\*.*\\*/)"); + static QRegExp commentRx(R"((//.*(\n|$)|/\*.*\*/))"); commentRx.setMinimal(true); ss.remove(commentRx); @@ -200,7 +200,7 @@ std::pair QssParser::parseFormatType const std::pair invalid{FormatType::Invalid, MessageLabel::None}; - static const QRegExp rx("ChatLine(?:::(\\w+))?(?:#([\\w\\-]+))?(?:\\[([=-,\\\"\\w\\s]+)\\])?"); + static const QRegExp rx(R"(ChatLine(?:::(\w+))?(?:#([\w\-]+))?(?:\[([=-,\"\w\s]+)\])?)"); // $1: subelement; $2: msgtype; $3: conditionals if (!rx.exactMatch(decl)) { qWarning() << Q_FUNC_INFO << tr("Invalid block declaration: %1").arg(decl); @@ -279,7 +279,7 @@ std::pair QssParser::parseFormatType } // Next up: conditional (formats, labels, nickhash) - static const QRegExp condRx("\\s*([\\w\\-]+)\\s*=\\s*\"(\\w+)\"\\s*"); + static const QRegExp condRx(R"lit(\s*([\w\-]+)\s*=\s*"(\w+)"\s*)lit"); if (!conditions.isEmpty()) { foreach(const QString &cond, conditions.split(',', QString::SkipEmptyParts)) { if (!condRx.exactMatch(cond)) { @@ -359,7 +359,7 @@ UiStyle::ItemFormatType QssParser::parseItemFormatType(const QString &decl) { using ItemFormatType = UiStyle::ItemFormatType; - static const QRegExp rx("(Chat|Nick)ListItem(?:\\[([=-,\\\"\\w\\s]+)\\])?"); + static const QRegExp rx(R"((Chat|Nick)ListItem(?:\[([=-,\"\w\s]+)\])?)"); // $1: item type; $2: properties if (!rx.exactMatch(decl)) { qWarning() << Q_FUNC_INFO << tr("Invalid block declaration: %1").arg(decl); @@ -374,7 +374,7 @@ UiStyle::ItemFormatType QssParser::parseItemFormatType(const QString &decl) QString type, state; if (!properties.isEmpty()) { QHash props; - static const QRegExp propRx("\\s*([\\w\\-]+)\\s*=\\s*\"([\\w\\-]+)\"\\s*"); + static const QRegExp propRx(R"lit(\s*([\w\-]+)\s*=\s*"([\w\-]+)"\s*)lit"); foreach(const QString &prop, properties.split(',', QString::SkipEmptyParts)) { if (!propRx.exactMatch(prop)) { qWarning() << Q_FUNC_INFO << tr("Invalid proplist %1").arg(prop); @@ -539,7 +539,7 @@ QBrush QssParser::parseBrush(const QString &str, bool *ok) // [0-9] Match any digit from 0-9 // Note that '\' must be escaped as '\\' // Helpful interactive website for debugging and explaining: https://regex101.com/ - static const QRegExp rx("palette\\s*\\(\\s*([a-z-0-9]+)\\s*\\)"); + static const QRegExp rx(R"(palette\s*\(\s*([a-z-0-9]+)\s*\))"); if (!rx.exactMatch(str)) { qWarning() << Q_FUNC_INFO << tr("Invalid palette color role specification: %1").arg(str); return QBrush(); @@ -552,8 +552,8 @@ QBrush QssParser::parseBrush(const QString &str, bool *ok) return QBrush(); } else if (str.startsWith("qlineargradient")) { - static const QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*"); - static const QRegExp rx(QString("qlineargradient\\s*\\(\\s*x1:%1,\\s*y1:%1,\\s*x2:%1,\\s*y2:%1,(.+)\\)").arg(rxFloat)); + static const QString rxFloat(R"(\s*(-?\s*[0-9]*\.?[0-9]+)\s*)"); + static const QRegExp rx(QString(R"(qlineargradient\s*\(\s*x1:%1,\s*y1:%1,\s*x2:%1,\s*y2:%1,(.+)\))").arg(rxFloat)); if (!rx.exactMatch(str)) { qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str); return QBrush(); @@ -575,8 +575,8 @@ QBrush QssParser::parseBrush(const QString &str, bool *ok) return QBrush(gradient); } else if (str.startsWith("qconicalgradient")) { - static const QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*"); - static const QRegExp rx(QString("qconicalgradient\\s*\\(\\s*cx:%1,\\s*cy:%1,\\s*angle:%1,(.+)\\)").arg(rxFloat)); + static const QString rxFloat(R"(\s*(-?\s*[0-9]*\.?[0-9]+)\s*)"); + static const QRegExp rx(QString(R"(qconicalgradient\s*\(\s*cx:%1,\s*cy:%1,\s*angle:%1,(.+)\))").arg(rxFloat)); if (!rx.exactMatch(str)) { qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str); return QBrush(); @@ -597,8 +597,8 @@ QBrush QssParser::parseBrush(const QString &str, bool *ok) return QBrush(gradient); } else if (str.startsWith("qradialgradient")) { - static const QString rxFloat("\\s*(-?\\s*[0-9]*\\.?[0-9]+)\\s*"); - static const QRegExp rx(QString("qradialgradient\\s*\\(\\s*cx:%1,\\s*cy:%1,\\s*radius:%1,\\s*fx:%1,\\s*fy:%1,(.+)\\)").arg(rxFloat)); + static const QString rxFloat(R"(\s*(-?\s*[0-9]*\.?[0-9]+)\s*)"); + static const QRegExp rx(QString(R"(qradialgradient\s*\(\s*cx:%1,\s*cy:%1,\s*radius:%1,\s*fx:%1,\s*fy:%1,(.+)\))").arg(rxFloat)); if (!rx.exactMatch(str)) { qWarning() << Q_FUNC_INFO << tr("Invalid gradient declaration: %1").arg(str); return QBrush(); @@ -666,7 +666,7 @@ QColor QssParser::parseColor(const QString &str) QssParser::ColorTuple QssParser::parseColorTuple(const QString &str) { ColorTuple result; - static const QRegExp rx("\\(((\\s*[0-9]{1,3}%?\\s*)(,\\s*[0-9]{1,3}%?\\s*)*)\\)"); + static const QRegExp rx(R"(\(((\s*[0-9]{1,3}%?\s*)(,\s*[0-9]{1,3}%?\s*)*)\))"); if (!rx.exactMatch(str.trimmed())) { return ColorTuple(); } @@ -696,7 +696,7 @@ QGradientStops QssParser::parseGradientStops(const QString &str_) QString str = str_; QGradientStops result; static const QString rxFloat("(0?\\.[0-9]+|[01])"); // values between 0 and 1 - static const QRegExp rx(QString("\\s*,?\\s*stop:\\s*(%1)\\s+([^:]+)(,\\s*stop:|$)").arg(rxFloat)); + static const QRegExp rx(QString(R"(\s*,?\s*stop:\s*(%1)\s+([^:]+)(,\s*stop:|$))").arg(rxFloat)); int idx; while ((idx = rx.indexIn(str)) == 0) { qreal x = rx.cap(1).toDouble(); diff --git a/src/uisupport/tabcompleter.cpp b/src/uisupport/tabcompleter.cpp index 957ddb00..ae37fd96 100644 --- a/src/uisupport/tabcompleter.cpp +++ b/src/uisupport/tabcompleter.cpp @@ -80,8 +80,8 @@ void TabCompleter::buildCompletionList() if (!_currentNetwork) return; - QString tabAbbrev = _lineEdit->text().left(_lineEdit->cursorPosition()).section(QRegExp("[^#\\w\\d-_\\[\\]{}|`^.\\\\]"), -1, -1); - QRegExp regex(QString("^[-_\\[\\]{}|`^.\\\\]*").append(QRegExp::escape(tabAbbrev)), Qt::CaseInsensitive); + QString tabAbbrev = _lineEdit->text().left(_lineEdit->cursorPosition()).section(QRegExp(R"([^#\w\d-_\[\]{}|`^.\\])"), -1, -1); + QRegExp regex(QString(R"(^[-_\[\]{}|`^.\\]*)").append(QRegExp::escape(tabAbbrev)), Qt::CaseInsensitive); // channel completion - add all channels of the current network to the map if (tabAbbrev.startsWith('#')) { -- 2.20.1