Plugins M-V: Make static QRegularExpression instances static const

Change-Id: I291e61ac30786dfceda330d3dc73352da719c7d0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2024-11-20 12:19:53 +01:00
parent 7c97a2b9f8
commit 116d5224e9
32 changed files with 57 additions and 48 deletions

View File

@@ -169,8 +169,8 @@ QString MercurialCommitWidget::repoRoot() const
QString MercurialCommitWidget::cleanupDescription(const QString &input) const
{
const QRegularExpression commentLine(QLatin1String("^HG:[^\\n]*(\\n|$)"),
QRegularExpression::MultilineOption);
static const QRegularExpression commentLine(QLatin1String("^HG:[^\\n]*(\\n|$)"),
QRegularExpression::MultilineOption);
QString message = input;
message.remove(commentLine);
return message;

View File

@@ -15,9 +15,9 @@
namespace MesonProjectManager::Internal {
static QRegularExpression &regExp()
static const QRegularExpression &regExp()
{
static QRegularExpression s_regexp{R"('([^']+)'+|([^', ]+)[, ]*)"};
static const QRegularExpression s_regexp{R"('([^']+)'+|([^', ]+)[, ]*)"};
return s_regexp;
}

View File

@@ -107,7 +107,7 @@ bool NimToolchain::parseVersion(const FilePath &path, std::tuple<int, int, int>
const QString version = process.readAllStandardOutput().section('\n', 0, 0);
if (version.isEmpty())
return false;
const QRegularExpression regex("(\\d+)\\.(\\d+)\\.(\\d+)");
static const QRegularExpression regex("(\\d+)\\.(\\d+)\\.(\\d+)");
const QRegularExpressionMatch match = regex.match(version);
if (!match.hasMatch())
return false;

View File

@@ -29,7 +29,7 @@ PendingChangesDialog::PendingChangesDialog(const QString &data, QWidget *parent)
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
if (!data.isEmpty()) {
const QRegularExpression r(QLatin1String("Change\\s(\\d+?).*?\\s\\*?pending\\*?\\s(.+?)\n"));
static const QRegularExpression r("Change\\s(\\d+?).*?\\s\\*?pending\\*?\\s(.+?)\n");
QListWidgetItem *item;
QRegularExpressionMatchIterator it = r.globalMatch(data);
while (it.hasNext()) {

View File

@@ -731,7 +731,8 @@ void PerforcePluginPrivate::startSubmitProject()
const QStringList filesLines = filesResult.stdOut.split(QLatin1Char('\n'));
QStringList depotFileNames;
for (const QString &line : filesLines) {
depotFileNames.append(line.left(line.lastIndexOf(QRegularExpression("#[0-9]+\\s-\\s"))));
static const QRegularExpression regexp("#[0-9]+\\s-\\s");
depotFileNames.append(line.left(line.lastIndexOf(regexp)));
}
if (depotFileNames.isEmpty()) {
VcsOutputWindow::appendWarning(Tr::tr("Project has no files"));
@@ -1447,7 +1448,7 @@ QString PerforcePluginPrivate::clientFilePath(const QString &serverFilePath)
if (response.error)
return {};
const QRegularExpression r("\\.\\.\\.\\sclientFile\\s(.+?)\n");
static const QRegularExpression r("\\.\\.\\.\\sclientFile\\s(.+?)\n");
const QRegularExpressionMatch match = r.match(response.stdOut);
return match.hasMatch() ? match.captured(1).trimmed() : QString();
}
@@ -1462,7 +1463,7 @@ QString PerforcePluginPrivate::pendingChangesData()
if (userResponse.error)
return {};
const QRegularExpression r("User\\sname:\\s(\\S+?)\\s*?\n");
static const QRegularExpression r("User\\sname:\\s(\\S+?)\\s*?\n");
QTC_ASSERT(r.isValid(), return QString());
const QRegularExpressionMatch match = r.match(userResponse.stdOut);
const QString user = match.hasMatch() ? match.captured(1).trimmed() : QString();

View File

@@ -48,7 +48,7 @@ bool PerforceSubmitEditor::setFileContents(const QByteArray &contents)
bool PerforceSubmitEditor::parseText(QString text)
{
QRegularExpression formField(QLatin1String("^\\S+:"));
static const QRegularExpression formField("^\\S+:");
const QString newLine = QString(QLatin1Char('\n'));
int matchLen;
@@ -94,7 +94,7 @@ void PerforceSubmitEditor::updateFields()
lines.removeFirst(); // that is the line break after 'Description:'
lines.removeLast(); // that is the empty line at the end
const QRegularExpression leadingTabPattern("^\\t");
static const QRegularExpression leadingTabPattern("^\\t");
QTC_CHECK(leadingTabPattern.isValid());
lines.replaceInStrings(leadingTabPattern, QString());
@@ -122,7 +122,8 @@ void PerforceSubmitEditor::updateEntries()
while (!lines.empty() && lines.last().isEmpty())
lines.removeLast();
// Description
lines.replaceInStrings(QRegularExpression("^"), tab);
static const QRegularExpression regexp("^");
lines.replaceInStrings(regexp, tab);
m_entries.insert(QLatin1String("Description"), newLine + lines.join(newLine) + QLatin1String("\n\n"));
QString files = newLine;
// Re-build the file spec '<tab>file#add' from the user data

View File

@@ -472,7 +472,8 @@ Abi Abi::abiFromTargetTriplet(const QString &triple)
if (machine.isEmpty())
return {};
const QStringList parts = machine.split(QRegularExpression("[ /-]"));
static const QRegularExpression splitRegexp("[ /-]");
const QStringList parts = machine.split(splitRegexp);
Architecture arch = UnknownArchitecture;
OS os = UnknownOS;

View File

@@ -454,7 +454,7 @@ void GccToolchain::setInstallDir(const FilePath &installDir)
QString GccToolchain::defaultDisplayName() const
{
QString type = typeDisplayName();
const QRegularExpression regexp(binaryRegexp);
static const QRegularExpression regexp(binaryRegexp);
const QRegularExpressionMatch match = regexp.match(compilerCommand().fileName());
if (match.lastCapturedIndex() >= 1)
type += ' ' + match.captured(1);

View File

@@ -60,7 +60,7 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k, bool &isDefaultKit, bool
"which for example determines the name of the shadow build directory."
"</p></body></html>").arg(QLatin1String("Kit:FileSystemName"));
m_fileSystemFriendlyNameLineEdit->setToolTip(toolTip);
QRegularExpression fileSystemFriendlyNameRegexp(QLatin1String("^[A-Za-z0-9_-]*$"));
static const QRegularExpression fileSystemFriendlyNameRegexp(QLatin1String("^[A-Za-z0-9_-]*$"));
Q_ASSERT(fileSystemFriendlyNameRegexp.isValid());
m_fileSystemFriendlyNameLineEdit->setValidator(new QRegularExpressionValidator(fileSystemFriendlyNameRegexp, m_fileSystemFriendlyNameLineEdit));

View File

@@ -2284,8 +2284,8 @@ ClangClInfo ClangClInfo::getInfo(const FilePath &filePath)
static const auto parser = [](const QString &stdOut, const QString &) {
ClangClInfo info;
const QRegularExpressionMatch versionMatch
= QRegularExpression("clang version (\\d+(\\.\\d+)+)").match(stdOut);
static const QRegularExpression regexp("clang version (\\d+(\\.\\d+)+)");
const QRegularExpressionMatch versionMatch = regexp.match(stdOut);
if (versionMatch.hasMatch())
info.m_version = QVersionNumber::fromString(versionMatch.captured(1));
const QString targetKey = "Target:";

View File

@@ -176,7 +176,8 @@ namespace {
static QString generateSuffix(const QString &suffix)
{
QString result = suffix;
result.replace(QRegularExpression("[^a-zA-Z0-9_.-]"), QString('_')); // replace fishy character
static const QRegularExpression regexp("[^a-zA-Z0-9_.-]");
result.replace(regexp, QString('_')); // replace fishy character
if (!result.startsWith('.'))
result.prepend('.');
return result;

View File

@@ -74,7 +74,7 @@ QString PySideInstaller::usedPySide(const QString &text, const QString &mimeType
{
using namespace Python::Constants;
if (mimeType == C_PY_MIMETYPE || mimeType == C_PY3_MIMETYPE || mimeType == C_PY_GUI_MIMETYPE) {
static QRegularExpression
static const QRegularExpression
scanner("^\\s*(import|from)\\s+(PySide\\d)", QRegularExpression::MultilineOption);
const QRegularExpressionMatch match = scanner.match(text);
return match.captured(2);

View File

@@ -370,7 +370,7 @@ void PythonBuildSystem::parse()
*/
static void expandEnvironmentVariables(const Environment &env, QString &string)
{
const QRegularExpression candidate("\\$\\$\\((.+)\\)");
static const QRegularExpression candidate("\\$\\$\\((.+)\\)");
QRegularExpressionMatch match;
int index = string.indexOf(candidate, 0, &match);

View File

@@ -361,7 +361,7 @@ QVariantMap DefaultPropertyProvider::autoGeneratedProperties(const ProjectExplor
}
if (targetAbi.os() == ProjectExplorer::Abi::DarwinOS) {
// Reverse engineer the Xcode developer path from the compiler path
const QRegularExpression compilerRe(
static const QRegularExpression compilerRe(
QStringLiteral("^(?<developerpath>.*)/Toolchains/(?:.+)\\.xctoolchain/usr/bin$"));
const QRegularExpressionMatch compilerReMatch = compilerRe.match(cxxCompilerPath.absolutePath().toString());
if (compilerReMatch.hasMatch()) {

View File

@@ -48,7 +48,8 @@ static QString toJSLiteral(const bool b)
static QString toJSLiteral(const QString &str)
{
QString js = str;
js.replace(QRegularExpression("([\\\\\"])"), "\\\\1");
static const QRegularExpression regexp("([\\\\\"])");
js.replace(regexp, "\\\\1");
js.prepend('"');
js.append('"');
return js;

View File

@@ -32,7 +32,7 @@ const char qt_file_dialog_filter_reg_exp[] =
static QStringList qt_clean_filter_list(const QString &filter)
{
const QRegularExpression regexp(qt_file_dialog_filter_reg_exp);
static const QRegularExpression regexp(qt_file_dialog_filter_reg_exp);
const QRegularExpressionMatch match = regexp.match(filter);
QString f = filter;
if (match.hasMatch())

View File

@@ -24,7 +24,8 @@ namespace QmakeProjectManager::Internal {
static QString headerGuard(const QString &header)
{
return header.toUpper().replace(QRegularExpression("[^A-Z0-9]+"), QString("_"));
static const QRegularExpression regexp("[^A-Z0-9]+");
return header.toUpper().replace(regexp, QString("_"));
}
struct ProjectContents {

View File

@@ -158,7 +158,7 @@ bool QmlJSHoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Docum
const HelpItem::Links links = helpItem.links();
// Check if the module name contains a major version.
static QRegularExpression version("^([^\\d]*)(\\d+)\\.*\\d*$");
static const QRegularExpression version("^([^\\d]*)(\\d+)\\.*\\d*$");
const QRegularExpressionMatch m = version.match(moduleName);
if (m.hasMatch()) {
QMap<QString, QUrl> filteredUrlMap;

View File

@@ -219,7 +219,7 @@ static QString getInitialDetails(const QmlEventType &event)
if (event.rangeType() == Javascript)
details = Tr::tr("anonymous function");
} else {
QRegularExpression rewrite(QLatin1String("^\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)$"));
static const QRegularExpression rewrite("^\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)$");
QRegularExpressionMatch match = rewrite.match(details);
if (match.hasMatch())
details = match.captured(1) + QLatin1String(": ") + match.captured(3);

View File

@@ -84,7 +84,7 @@ const QString getMainQmlFile(const Utils::FilePath &projectFilePath)
{
const QString defaultReturn = "content/App.qml";
const QString data = readFileContents(projectFilePath);
QRegularExpression regexp(R"x(mainFile: "(.*)")x");
static const QRegularExpression regexp(R"x(mainFile: "(.*)")x");
QRegularExpressionMatch match = regexp.match(data);
if (!match.hasMatch())
return defaultReturn;
@@ -105,8 +105,8 @@ const Resolution resolutionFromConstants(const Utils::FilePath &projectFilePath)
if (!reader.fetch(Utils::FilePath::fromString(fileName)))
return {};
const QByteArray data = reader.data();
const QRegularExpression regexpWidth(R"x(readonly\s+property\s+int\s+width:\s+(\d*))x");
const QRegularExpression regexpHeight(R"x(readonly\s+property\s+int\s+height:\s+(\d*))x");
static const QRegularExpression regexpWidth(R"x(readonly\s+property\s+int\s+width:\s+(\d*))x");
static const QRegularExpression regexpHeight(R"x(readonly\s+property\s+int\s+height:\s+(\d*))x");
int width = -1;
int height = -1;
QRegularExpressionMatch match = regexpHeight.match(QString::fromUtf8(data));

View File

@@ -66,7 +66,8 @@ QString QnxVersionNumber::segment(int index) const
QnxVersionNumber QnxVersionNumber::fromTargetName(const QString &targetName)
{
return fromFileName(targetName, QRegularExpression("^target_(.*)$"));
static const QRegularExpression regexp("^target_(.*)$");
return fromFileName(targetName, regexp);
}
QnxVersionNumber QnxVersionNumber::fromFileName(const QString &fileName, const QRegularExpression &regExp)

View File

@@ -106,8 +106,8 @@ void Slog2InfoRunner::processLogLine(const QString &line)
// The "\\s+(\\b.*)?$" represents a space followed by a message. We are unable to determinate
// how many spaces represent separators and how many are a part of the messages, so resulting
// messages has all whitespaces at the beginning of the message trimmed.
static QRegularExpression regexp(QLatin1String(
"^[a-zA-Z]+\\s+([0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+)\\s+(\\S+)(\\s+(\\S+))?\\s+([0-9]+)\\s+(.*)?$"));
static const QRegularExpression regexp(
"^[a-zA-Z]+\\s+([0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+)\\s+(\\S+)(\\s+(\\S+))?\\s+([0-9]+)\\s+(.*)?$");
const QRegularExpressionMatch match = regexp.match(line);
if (!match.hasMatch())

View File

@@ -1824,7 +1824,7 @@ FilePath QtVersionPrivate::mkspecFromVersionInfo(const QHash<ProKey, ProString>
if (temp.size() == 2) {
QString possibleFullPath = QString::fromLocal8Bit(temp.at(1).trimmed().constData());
if (possibleFullPath.contains('$')) { // QTBUG-28792
const QRegularExpression rex("\\binclude\\(([^)]+)/qmake\\.conf\\)");
static const QRegularExpression rex("\\binclude\\(([^)]+)/qmake\\.conf\\)");
const QRegularExpressionMatch match = rex.match(QString::fromLocal8Bit(f2.readAll()));
if (match.hasMatch()) {
possibleFullPath = mkspecFullPath.toString() + '/'
@@ -2134,7 +2134,8 @@ static QStringList extractFieldsFromBuildString(const QByteArray &buildString)
if (buildString.isEmpty() || buildString.size() > 4096)
return {};
const QRegularExpression buildStringMatcher("^Qt "
static const QRegularExpression buildStringMatcher(
"^Qt "
"([\\d\\.a-zA-Z]*) " // Qt version
"\\("
"([\\w_-]+) " // Abi information

View File

@@ -41,8 +41,8 @@ QWidget *TreeItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
if (index.isValid()) {
auto edit = new QLineEdit(parent);
edit->setFocusPolicy(Qt::StrongFocus);
QRegularExpression rx("^(?!xml)[_a-z][a-z0-9-._]*$");
rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
static const QRegularExpression rx("^(?!xml)[_a-z][a-z0-9-._]*$",
QRegularExpression::CaseInsensitiveOption);
edit->setValidator(new QRegularExpressionValidator(rx, parent));
return edit;
}

View File

@@ -28,9 +28,8 @@ QWidget *SCAttributeItemDelegate::createEditor(QWidget *parent, const QStyleOpti
if (index.column() == 0) {
auto edit = new QLineEdit(parent);
edit->setFocusPolicy(Qt::StrongFocus);
QRegularExpression rx("^(?!xml)[_a-z][a-z0-9-._]*$");
rx.setPatternOptions(QRegularExpression::CaseInsensitiveOption);
static const QRegularExpression rx("^(?!xml)[_a-z][a-z0-9-._]*$",
QRegularExpression::CaseInsensitiveOption);
edit->setValidator(new QRegularExpressionValidator(rx, parent));
return edit;
}

View File

@@ -514,7 +514,7 @@ void ObjectsMapEditorWidget::onPasteSymbolicNameTriggered()
return;
// if name is not valid at all refuse to do anything
const QRegularExpression validName("^:[^\t\n\r\f\b\v\a]+$");
static const QRegularExpression validName("^:[^\t\n\r\f\b\v\a]+$");
if (!validName.match(symbolicName).hasMatch())
return;

View File

@@ -137,7 +137,7 @@ ValidatingPropertyNameLineEdit::ValidatingPropertyNameLineEdit(const QStringList
if (!edit)
return false;
const QRegularExpression identifier("^[a-zA-Z0-9_]+$");
static const QRegularExpression identifier("^[a-zA-Z0-9_]+$");
const QString &value = edit->text();
return !m_forbidden.contains(value) && identifier.match(value).hasMatch();

View File

@@ -87,7 +87,7 @@ static expected_str<void> loadXdefaults(const FilePath &path)
if (!readResult)
return make_unexpected(readResult.error());
QRegularExpression re(R"(.*\*(color[0-9]{1,2}|foreground|background):\s*(#[0-9a-f]{6}))");
static const QRegularExpression re(R"(.*\*(color[0-9]{1,2}|foreground|background):\s*(#[0-9a-f]{6}))");
for (const QByteArray &line : readResult->split('\n')) {
if (line.trimmed().startsWith('!'))

View File

@@ -80,7 +80,7 @@ IAssistProposal *DocumentContentCompletionProcessor::performAsync()
const QString wordUnderCursor = interface()->textAt(pos, length);
const QString text = interface()->textDocument()->toPlainText();
const QRegularExpression wordRE("([\\p{L}_][\\p{L}0-9_]{2,})");
static const QRegularExpression wordRE("([\\p{L}_][\\p{L}0-9_]{2,})");
QSet<QString> words;
QRegularExpressionMatchIterator it = wordRE.globalMatch(text);
int wordUnderCursorFound = 0;

View File

@@ -66,7 +66,7 @@ bool StorageSettings::removeTrailingWhitespace(const QString &fileName) const
const QString ignoreFileTypesRegExp(R"(\s*((?>\*\.)?[\w\d\.\*]+)[,;]?\s*)");
// use the ignore-files regex to extract the specified file patterns
QRegularExpression re(ignoreFileTypesRegExp);
static const QRegularExpression re(ignoreFileTypesRegExp);
QRegularExpressionMatchIterator iter = re.globalMatch(m_ignoreFileTypes);
while (iter.hasNext()) {

View File

@@ -2457,7 +2457,8 @@ void TextEditorWidget::joinLines()
QString cutLine = c.selectedText();
// Collapse leading whitespaces to one or insert whitespace
cutLine.replace(QRegularExpression(QLatin1String("^\\s*")), QLatin1String(" "));
static const QRegularExpression regexp("^\\s*");
cutLine.replace(regexp, QLatin1String(" "));
c.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
c.removeSelectedText();
@@ -8815,7 +8816,7 @@ void TextEditorWidget::autoIndent()
void TextEditorWidget::rewrapParagraph()
{
const int paragraphWidth = marginSettings().m_marginColumn;
const QRegularExpression anyLettersOrNumbers("\\w");
static const QRegularExpression anyLettersOrNumbers("\\w");
const TabSettings ts = d->m_document->tabSettings();
QTextCursor cursor = textCursor();
@@ -8868,7 +8869,7 @@ void TextEditorWidget::rewrapParagraph()
}
// Find end of paragraph.
const QRegularExpression immovableDoxygenCommand(doxygenPrefix + "[@\\\\][a-zA-Z]{2,}");
static const QRegularExpression immovableDoxygenCommand(doxygenPrefix + "[@\\\\][a-zA-Z]{2,}");
QTC_CHECK(immovableDoxygenCommand.isValid());
while (cursor.movePosition(QTextCursor::NextBlock, QTextCursor::KeepAnchor)) {
QString text = cursor.block().text();

View File

@@ -1155,7 +1155,8 @@ HeobDialog::HeobDialog(QWidget *parent) :
QtcSettings *settings = Core::ICore::settings();
bool hasSelProfile = settings->contains(heobProfileC);
const QString selProfile = hasSelProfile ? settings->value(heobProfileC).toString() : "Heob";
m_profiles = settings->childGroups().filter(QRegularExpression("^Heob\\.Profile\\."));
static const QRegularExpression regexp("^Heob\\.Profile\\.");
m_profiles = settings->childGroups().filter(regexp);
auto layout = new QVBoxLayout;
// disable resizing