mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-07 13:20:25 +00:00
Migrate from QRegExp to more modern QRegularExpression
This commit is contained in:
parent
7c078883d5
commit
307a60e87c
@ -205,11 +205,12 @@ void Launcher::GraphicsPage::saveSettings()
|
|||||||
int cHeight = 0;
|
int cHeight = 0;
|
||||||
if (standardRadioButton->isChecked())
|
if (standardRadioButton->isChecked())
|
||||||
{
|
{
|
||||||
QRegExp resolutionRe(QString("(\\d+) x (\\d+).*"));
|
QRegularExpression resolutionRe(QRegularExpression::anchoredPattern(QString("(\\d+) x (\\d+).*")));
|
||||||
if (resolutionRe.exactMatch(resolutionComboBox->currentText().simplified()))
|
QRegularExpressionMatch match = resolutionRe.match(resolutionComboBox->currentText().simplified());
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
cWidth = resolutionRe.cap(1).toInt();
|
cWidth = match.captured(1).toInt();
|
||||||
cHeight = resolutionRe.cap(2).toInt();
|
cHeight = match.captured(2).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -20,7 +20,8 @@ Launcher::TextInputDialog::TextInputDialog(const QString& title, const QString&
|
|||||||
label->setText(text);
|
label->setText(text);
|
||||||
|
|
||||||
// Line edit
|
// Line edit
|
||||||
QValidator* validator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
QValidator* validator
|
||||||
|
= new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
||||||
mLineEdit = new LineEdit(this);
|
mLineEdit = new LineEdit(this);
|
||||||
mLineEdit->setValidator(validator);
|
mLineEdit->setValidator(validator);
|
||||||
mLineEdit->setCompleter(nullptr);
|
mLineEdit->setCompleter(nullptr);
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
@ -362,7 +363,7 @@ bool CS::Editor::makeIPCServer()
|
|||||||
mServer->listen("dummy");
|
mServer->listen("dummy");
|
||||||
QString fullPath = mServer->fullServerName();
|
QString fullPath = mServer->fullServerName();
|
||||||
mServer->close();
|
mServer->close();
|
||||||
fullPath.remove(QRegExp("dummy$"));
|
fullPath.remove(QRegularExpression("dummy$"));
|
||||||
fullPath += mIpcServerName;
|
fullPath += mIpcServerName;
|
||||||
const auto path = Files::pathFromQString(fullPath);
|
const auto path = Files::pathFromQString(fullPath);
|
||||||
if (exists(path))
|
if (exists(path))
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
#include "../world/columns.hpp"
|
#include "../world/columns.hpp"
|
||||||
#include "../world/idtablebase.hpp"
|
#include "../world/idtablebase.hpp"
|
||||||
@ -57,9 +57,11 @@ bool CSMFilter::TextNode::test(const CSMWorld::IdTableBase& table, int row, cons
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/// \todo make pattern syntax configurable
|
/// \todo make pattern syntax configurable
|
||||||
QRegExp regExp(QString::fromUtf8(mText.c_str()), Qt::CaseInsensitive);
|
QRegularExpression regExp(QRegularExpression::anchoredPattern(QString::fromUtf8(mText.c_str())),
|
||||||
|
QRegularExpression::CaseInsensitiveOption);
|
||||||
|
QRegularExpressionMatch match = regExp.match(string);
|
||||||
|
|
||||||
return regExp.exactMatch(string);
|
return match.hasMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> CSMFilter::TextNode::getReferencedColumns() const
|
std::vector<int> CSMFilter::TextNode::getReferencedColumns() const
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "search.hpp"
|
#include "search.hpp"
|
||||||
|
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -49,10 +49,12 @@ void CSMTools::Search::searchRegExCell(const CSMWorld::IdTableBase* model, const
|
|||||||
QString text = model->data(index).toString();
|
QString text = model->data(index).toString();
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
QRegularExpressionMatch match;
|
||||||
|
|
||||||
while ((pos = mRegExp.indexIn(text, pos)) != -1)
|
while ((match = mRegExp.match(text, pos)).hasMatch())
|
||||||
{
|
{
|
||||||
int length = mRegExp.matchedLength();
|
pos = match.capturedStart();
|
||||||
|
int length = match.capturedLength();
|
||||||
|
|
||||||
std::ostringstream hint;
|
std::ostringstream hint;
|
||||||
hint << (writable ? 'R' : 'r') << ": " << model->getColumnId(index.column()) << " " << pos << " " << length;
|
hint << (writable ? 'R' : 'r') << ": " << model->getColumnId(index.column()) << " " << pos << " " << length;
|
||||||
@ -138,7 +140,7 @@ CSMTools::Search::Search(Type type, bool caseSensitive, const std::string& value
|
|||||||
throw std::logic_error("Invalid search parameter (string)");
|
throw std::logic_error("Invalid search parameter (string)");
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::Search::Search(Type type, bool caseSensitive, const QRegExp& value)
|
CSMTools::Search::Search(Type type, bool caseSensitive, const QRegularExpression& value)
|
||||||
: mType(type)
|
: mType(type)
|
||||||
, mRegExp(value)
|
, mRegExp(value)
|
||||||
, mValue(0)
|
, mValue(0)
|
||||||
@ -148,7 +150,7 @@ CSMTools::Search::Search(Type type, bool caseSensitive, const QRegExp& value)
|
|||||||
, mPaddingBefore(10)
|
, mPaddingBefore(10)
|
||||||
, mPaddingAfter(10)
|
, mPaddingAfter(10)
|
||||||
{
|
{
|
||||||
mRegExp.setCaseSensitivity(mCase ? Qt::CaseSensitive : Qt::CaseInsensitive);
|
mRegExp.setPatternOptions(mCase ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption);
|
||||||
if (type != Type_TextRegEx && type != Type_IdRegEx)
|
if (type != Type_TextRegEx && type != Type_IdRegEx)
|
||||||
throw std::logic_error("Invalid search parameter (RegExp)");
|
throw std::logic_error("Invalid search parameter (RegExp)");
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace CSMTools
|
|||||||
private:
|
private:
|
||||||
Type mType;
|
Type mType;
|
||||||
std::string mText;
|
std::string mText;
|
||||||
QRegExp mRegExp;
|
QRegularExpression mRegExp;
|
||||||
int mValue;
|
int mValue;
|
||||||
bool mCase;
|
bool mCase;
|
||||||
std::set<int> mColumns;
|
std::set<int> mColumns;
|
||||||
@ -66,7 +66,7 @@ namespace CSMTools
|
|||||||
|
|
||||||
Search(Type type, bool caseSensitive, const std::string& value);
|
Search(Type type, bool caseSensitive, const std::string& value);
|
||||||
|
|
||||||
Search(Type type, bool caseSensitive, const QRegExp& value);
|
Search(Type type, bool caseSensitive, const QRegularExpression& value);
|
||||||
|
|
||||||
Search(Type type, bool caseSensitive, int value);
|
Search(Type type, bool caseSensitive, int value);
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QRegExp>
|
|
||||||
#include <QRegExpValidator>
|
|
||||||
|
|
||||||
QString CSVDoc::FileWidget::getExtension() const
|
QString CSVDoc::FileWidget::getExtension() const
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QContextMenuEvent>
|
#include <QContextMenuEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
#include <apps/opencs/model/filter/parser.hpp>
|
#include <apps/opencs/model/filter/parser.hpp>
|
||||||
@ -136,8 +137,9 @@ void CSVFilter::EditWidget::createFilterRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldContent.isEmpty()
|
if (oldContent.isEmpty()
|
||||||
|| !oldContent.contains(QRegExp("^!.*$",
|
|| !oldContent.contains(QRegularExpression("^!.*$",
|
||||||
Qt::CaseInsensitive))) // if line edit is empty or it does not contain one shot filter go into replace mode
|
QRegularExpression::CaseInsensitiveOption))) // if line edit is empty or it does not contain one shot filter
|
||||||
|
// go into replace mode
|
||||||
{
|
{
|
||||||
replaceMode = true;
|
replaceMode = true;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,8 @@ CSMTools::Search CSVTools::SearchBox::getSearch() const
|
|||||||
case CSMTools::Search::Type_TextRegEx:
|
case CSMTools::Search::Type_TextRegEx:
|
||||||
case CSMTools::Search::Type_IdRegEx:
|
case CSMTools::Search::Type_IdRegEx:
|
||||||
|
|
||||||
return CSMTools::Search(type, caseSensitive, QRegExp(mText.text().toUtf8().data(), Qt::CaseInsensitive));
|
return CSMTools::Search(type, caseSensitive,
|
||||||
|
QRegularExpression(mText.text().toUtf8().data(), QRegularExpression::CaseInsensitiveOption));
|
||||||
|
|
||||||
case CSMTools::Search::Type_RecordState:
|
case CSMTools::Search::Type_RecordState:
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ CSVWorld::ScriptEdit::ScriptEdit(const CSMDoc::Document& document, ScriptHighlig
|
|||||||
, mTabCharCount(4)
|
, mTabCharCount(4)
|
||||||
, mMarkOccurrences(true)
|
, mMarkOccurrences(true)
|
||||||
, mDocument(document)
|
, mDocument(document)
|
||||||
, mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
|
, mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", QRegularExpression::CaseInsensitiveOption)
|
||||||
{
|
{
|
||||||
wrapLines(false);
|
wrapLines(false);
|
||||||
setTabWidth();
|
setTabWidth();
|
||||||
@ -186,7 +186,7 @@ void CSVWorld::ScriptEdit::dropEvent(QDropEvent* event)
|
|||||||
|
|
||||||
bool CSVWorld::ScriptEdit::stringNeedsQuote(const std::string& id) const
|
bool CSVWorld::ScriptEdit::stringNeedsQuote(const std::string& id) const
|
||||||
{
|
{
|
||||||
const QString string(QString::fromUtf8(id.c_str())); //<regex> is only for c++11, so let's use qregexp for now.
|
const QString string(QString::fromUtf8(id.c_str()));
|
||||||
// I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
|
// I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than…
|
||||||
return !(string.contains(mWhiteListQoutes));
|
return !(string.contains(mWhiteListQoutes));
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
@ -95,7 +95,7 @@ namespace CSVWorld
|
|||||||
private:
|
private:
|
||||||
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
|
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
|
||||||
const CSMDoc::Document& mDocument;
|
const CSMDoc::Document& mDocument;
|
||||||
const QRegExp mWhiteListQoutes;
|
const QRegularExpression mWhiteListQoutes;
|
||||||
|
|
||||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
@ -30,12 +30,12 @@ bool Wizard::IniSettings::readFile(QTextStream& stream)
|
|||||||
// Look for a square bracket, "'\\["
|
// Look for a square bracket, "'\\["
|
||||||
// that has one or more "not nothing" in it, "([^]]+)"
|
// that has one or more "not nothing" in it, "([^]]+)"
|
||||||
// and is closed with a square bracket, "\\]"
|
// and is closed with a square bracket, "\\]"
|
||||||
QRegExp sectionRe(QLatin1String("^\\[([^]]+)\\]"));
|
QRegularExpression sectionRe(QRegularExpression::anchoredPattern("^\\[([^]]+)\\]"));
|
||||||
|
|
||||||
// Find any character(s) that is/are not equal sign(s), "[^=]+"
|
// Find any character(s) that is/are not equal sign(s), "[^=]+"
|
||||||
// followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*"
|
// followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*"
|
||||||
// and one or more periods, "(.+)"
|
// and one or more periods, "(.+)"
|
||||||
QRegExp keyRe(QLatin1String("^([^=]+)\\s*=\\s*(.+)$"));
|
QRegularExpression keyRe(QLatin1String("^([^=]+)\\s*=\\s*(.+)$"));
|
||||||
|
|
||||||
QString currentSection;
|
QString currentSection;
|
||||||
|
|
||||||
@ -46,14 +46,18 @@ bool Wizard::IniSettings::readFile(QTextStream& stream)
|
|||||||
if (line.isEmpty() || line.startsWith(QLatin1Char(';')))
|
if (line.isEmpty() || line.startsWith(QLatin1Char(';')))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sectionRe.exactMatch(line))
|
QRegularExpressionMatch sectionMatch = sectionRe.match(line);
|
||||||
|
if (sectionMatch.hasMatch())
|
||||||
{
|
{
|
||||||
currentSection = sectionRe.cap(1);
|
currentSection = sectionMatch.captured(1);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else if (keyRe.indexIn(line) != -1)
|
|
||||||
|
QRegularExpressionMatch match = keyRe.match(line);
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
QString key = keyRe.cap(1).trimmed();
|
QString key = match.captured(1).trimmed();
|
||||||
QString value = keyRe.cap(2).trimmed();
|
QString value = match.captured(2).trimmed();
|
||||||
|
|
||||||
// Append the section, but only if there is one
|
// Append the section, but only if there is one
|
||||||
if (!currentSection.isEmpty())
|
if (!currentSection.isEmpty())
|
||||||
@ -71,12 +75,12 @@ bool Wizard::IniSettings::writeFile(const QString& path, QTextStream& stream)
|
|||||||
// Look for a square bracket, "'\\["
|
// Look for a square bracket, "'\\["
|
||||||
// that has one or more "not nothing" in it, "([^]]+)"
|
// that has one or more "not nothing" in it, "([^]]+)"
|
||||||
// and is closed with a square bracket, "\\]"
|
// and is closed with a square bracket, "\\]"
|
||||||
QRegExp sectionRe(QLatin1String("^\\[([^]]+)\\]"));
|
QRegularExpression sectionRe(QRegularExpression::anchoredPattern("^\\[([^]]+)\\]"));
|
||||||
|
|
||||||
// Find any character(s) that is/are not equal sign(s), "[^=]+"
|
// Find any character(s) that is/are not equal sign(s), "[^=]+"
|
||||||
// followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*"
|
// followed by an optional whitespace, an equal sign, and another optional whitespace, "\\s*=\\s*"
|
||||||
// and one or more periods, "(.+)"
|
// and one or more periods, "(.+)"
|
||||||
QRegExp keyRe(QLatin1String("^([^=]+)\\s*=\\s*(.+)$"));
|
QRegularExpression keyRe(QLatin1String("^([^=]+)\\s*=\\s*(.+)$"));
|
||||||
|
|
||||||
const QStringList keys(mSettings.keys());
|
const QStringList keys(mSettings.keys());
|
||||||
|
|
||||||
@ -85,7 +89,6 @@ bool Wizard::IniSettings::writeFile(const QString& path, QTextStream& stream)
|
|||||||
|
|
||||||
while (!stream.atEnd())
|
while (!stream.atEnd())
|
||||||
{
|
{
|
||||||
|
|
||||||
const QString line(stream.readLine());
|
const QString line(stream.readLine());
|
||||||
|
|
||||||
if (line.isEmpty() || line.startsWith(QLatin1Char(';')))
|
if (line.isEmpty() || line.startsWith(QLatin1Char(';')))
|
||||||
@ -94,14 +97,18 @@ bool Wizard::IniSettings::writeFile(const QString& path, QTextStream& stream)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sectionRe.exactMatch(line))
|
QRegularExpressionMatch sectionMatch = sectionRe.match(line);
|
||||||
|
if (sectionMatch.hasMatch())
|
||||||
{
|
{
|
||||||
buffer.append(line + QLatin1String("\n"));
|
buffer.append(line + QLatin1String("\n"));
|
||||||
currentSection = sectionRe.cap(1);
|
currentSection = sectionMatch.captured(1);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else if (keyRe.indexIn(line) != -1)
|
|
||||||
|
QRegularExpressionMatch match = keyRe.match(line);
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
QString key(keyRe.cap(1).trimmed());
|
QString key(match.captured(1).trimmed());
|
||||||
QString lookupKey(key);
|
QString lookupKey(key);
|
||||||
|
|
||||||
// Append the section, but only if there is one
|
// Append the section, but only if there is one
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "launchersettings.hpp"
|
#include "launchersettings.hpp"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
@ -90,7 +90,7 @@ bool Config::GameSettings::readUserFile(QTextStream& stream, bool ignoreContent)
|
|||||||
bool Config::GameSettings::readFile(QTextStream& stream, QMultiMap<QString, QString>& settings, bool ignoreContent)
|
bool Config::GameSettings::readFile(QTextStream& stream, QMultiMap<QString, QString>& settings, bool ignoreContent)
|
||||||
{
|
{
|
||||||
QMultiMap<QString, QString> cache;
|
QMultiMap<QString, QString> cache;
|
||||||
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
QRegularExpression keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
||||||
|
|
||||||
while (!stream.atEnd())
|
while (!stream.atEnd())
|
||||||
{
|
{
|
||||||
@ -99,11 +99,11 @@ bool Config::GameSettings::readFile(QTextStream& stream, QMultiMap<QString, QStr
|
|||||||
if (line.isEmpty() || line.startsWith("#"))
|
if (line.isEmpty() || line.startsWith("#"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (keyRe.indexIn(line) != -1)
|
QRegularExpressionMatch match = keyRe.match(line);
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
|
QString key = match.captured(1).trimmed();
|
||||||
QString key = keyRe.cap(1).trimmed();
|
QString value = match.captured(2).trimmed();
|
||||||
QString value = keyRe.cap(2).trimmed();
|
|
||||||
|
|
||||||
// Don't remove composing entries
|
// Don't remove composing entries
|
||||||
if (key != QLatin1String("data") && key != QLatin1String("fallback-archive")
|
if (key != QLatin1String("data") && key != QLatin1String("fallback-archive")
|
||||||
@ -206,10 +206,13 @@ bool Config::GameSettings::writeFile(QTextStream& stream)
|
|||||||
|
|
||||||
bool Config::GameSettings::isOrderedLine(const QString& line)
|
bool Config::GameSettings::isOrderedLine(const QString& line)
|
||||||
{
|
{
|
||||||
return line.contains(QRegExp("^\\s*fallback-archive\\s*=")) || line.contains(QRegExp("^\\s*fallback\\s*="))
|
return line.contains(QRegularExpression("^\\s*fallback-archive\\s*="))
|
||||||
|| line.contains(QRegExp("^\\s*data\\s*=")) || line.contains(QRegExp("^\\s*data-local\\s*="))
|
|| line.contains(QRegularExpression("^\\s*fallback\\s*="))
|
||||||
|| line.contains(QRegExp("^\\s*resources\\s*=")) || line.contains(QRegExp("^\\s*groundcover\\s*="))
|
|| line.contains(QRegularExpression("^\\s*data\\s*="))
|
||||||
|| line.contains(QRegExp("^\\s*content\\s*="));
|
|| line.contains(QRegularExpression("^\\s*data-local\\s*="))
|
||||||
|
|| line.contains(QRegularExpression("^\\s*resources\\s*="))
|
||||||
|
|| line.contains(QRegularExpression("^\\s*groundcover\\s*="))
|
||||||
|
|| line.contains(QRegularExpression("^\\s*content\\s*="));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Policy:
|
// Policy:
|
||||||
@ -268,7 +271,7 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
// +----------------------------------------------------------+
|
// +----------------------------------------------------------+
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
QRegExp settingRegex("^([^=]+)\\s*=\\s*([^,]+)(.*)$");
|
QRegularExpression settingRegex("^([^=]+)\\s*=\\s*([^,]+)(.*)$");
|
||||||
std::vector<QString> comments;
|
std::vector<QString> comments;
|
||||||
auto commentStart = fileCopy.end();
|
auto commentStart = fileCopy.end();
|
||||||
std::map<QString, std::vector<QString>> commentsMap;
|
std::map<QString, std::vector<QString>> commentsMap;
|
||||||
@ -279,9 +282,10 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
// save in a separate map of comments keyed by "ordered" line
|
// save in a separate map of comments keyed by "ordered" line
|
||||||
if (!comments.empty())
|
if (!comments.empty())
|
||||||
{
|
{
|
||||||
if (settingRegex.indexIn(*iter) != -1)
|
QRegularExpressionMatch match = settingRegex.match(*iter);
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
commentsMap[settingRegex.cap(1) + "=" + settingRegex.cap(2)] = comments;
|
commentsMap[match.captured(1) + "=" + match.captured(2)] = comments;
|
||||||
comments.clear();
|
comments.clear();
|
||||||
commentStart = fileCopy.end();
|
commentStart = fileCopy.end();
|
||||||
}
|
}
|
||||||
@ -290,14 +294,14 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
|
|
||||||
*iter = QString(); // "ordered" lines to be removed later
|
*iter = QString(); // "ordered" lines to be removed later
|
||||||
}
|
}
|
||||||
else if ((*iter).isEmpty() || (*iter).contains(QRegExp("^\\s*#")))
|
else if ((*iter).isEmpty() || (*iter).contains(QRegularExpression("^\\s*#")))
|
||||||
{
|
{
|
||||||
// comment line, save in temp buffer
|
// comment line, save in temp buffer
|
||||||
if (comments.empty())
|
if (comments.empty())
|
||||||
commentStart = iter;
|
commentStart = iter;
|
||||||
|
|
||||||
// special removed content processing
|
// special removed content processing
|
||||||
if ((*iter).contains(QRegExp("^##content\\s*=")))
|
if ((*iter).contains(QRegularExpression("^##content\\s*=")))
|
||||||
{
|
{
|
||||||
if (!comments.empty())
|
if (!comments.empty())
|
||||||
{
|
{
|
||||||
@ -313,11 +317,11 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int index = settingRegex.indexIn(*iter);
|
QRegularExpressionMatch match = settingRegex.match(*iter);
|
||||||
|
|
||||||
// blank or non-"ordered" line, write saved comments
|
// blank or non-"ordered" line, write saved comments
|
||||||
if (!comments.empty() && index != -1 && settingRegex.captureCount() >= 2
|
if (!comments.empty() && match.hasMatch() && settingRegex.captureCount() >= 2
|
||||||
&& mUserSettings.find(settingRegex.cap(1)) != mUserSettings.end())
|
&& mUserSettings.find(match.captured(1)) != mUserSettings.end())
|
||||||
{
|
{
|
||||||
if (commentStart == fileCopy.end())
|
if (commentStart == fileCopy.end())
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
@ -335,10 +339,10 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
// keep blank lines and non-"ordered" lines other than comments
|
// keep blank lines and non-"ordered" lines other than comments
|
||||||
|
|
||||||
// look for a key in the line
|
// look for a key in the line
|
||||||
if (index == -1 || settingRegex.captureCount() < 2)
|
if (!match.hasMatch() || settingRegex.captureCount() < 2)
|
||||||
{
|
{
|
||||||
// no key or first part of value found in line, replace with a null string which
|
// no key or first part of value found in line, replace with a null string which
|
||||||
// will be remved later
|
// will be removed later
|
||||||
*iter = QString();
|
*iter = QString();
|
||||||
comments.clear();
|
comments.clear();
|
||||||
commentStart = fileCopy.end();
|
commentStart = fileCopy.end();
|
||||||
@ -347,15 +351,16 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
|
|
||||||
// look for a matching key in user settings
|
// look for a matching key in user settings
|
||||||
*iter = QString(); // assume no match
|
*iter = QString(); // assume no match
|
||||||
QString key = settingRegex.cap(1);
|
QString key = match.captured(1);
|
||||||
QString keyVal = settingRegex.cap(1) + "=" + settingRegex.cap(2);
|
QString keyVal = match.captured(1) + "=" + match.captured(2);
|
||||||
QMultiMap<QString, QString>::const_iterator i = mUserSettings.find(key);
|
QMultiMap<QString, QString>::const_iterator i = mUserSettings.find(key);
|
||||||
while (i != mUserSettings.end() && i.key() == key)
|
while (i != mUserSettings.end() && i.key() == key)
|
||||||
{
|
{
|
||||||
QString settingLine = i.key() + "=" + i.value();
|
QString settingLine = i.key() + "=" + i.value();
|
||||||
if (settingRegex.indexIn(settingLine) != -1)
|
QRegularExpressionMatch keyMatch = settingRegex.match(settingLine);
|
||||||
|
if (keyMatch.hasMatch())
|
||||||
{
|
{
|
||||||
if ((settingRegex.cap(1) + "=" + settingRegex.cap(2)) == keyVal)
|
if ((keyMatch.captured(1) + "=" + keyMatch.captured(2)) == keyVal)
|
||||||
{
|
{
|
||||||
*iter = settingLine;
|
*iter = settingLine;
|
||||||
break;
|
break;
|
||||||
@ -374,7 +379,7 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
|
|
||||||
// Below is based on readFile() code, if that changes corresponding change may be
|
// Below is based on readFile() code, if that changes corresponding change may be
|
||||||
// required (for example duplicates may be inserted if the rules don't match)
|
// required (for example duplicates may be inserted if the rules don't match)
|
||||||
if (/*(*iter).isEmpty() ||*/ iter.contains(QRegExp("^\\s*#")))
|
if (/*(*iter).isEmpty() ||*/ iter.contains(QRegularExpression("^\\s*#")))
|
||||||
{
|
{
|
||||||
stream << iter << "\n";
|
stream << iter << "\n";
|
||||||
continue;
|
continue;
|
||||||
@ -413,13 +418,14 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
else
|
else
|
||||||
settingLine = it.key() + "=" + it.value();
|
settingLine = it.key() + "=" + it.value();
|
||||||
|
|
||||||
if (settingRegex.indexIn(settingLine) != -1)
|
QRegularExpressionMatch match = settingRegex.match(settingLine);
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
auto i = commentsMap.find(settingRegex.cap(1) + "=" + settingRegex.cap(2));
|
auto i = commentsMap.find(match.captured(1) + "=" + match.captured(2));
|
||||||
|
|
||||||
// check if previous removed content item with comments
|
// check if previous removed content item with comments
|
||||||
if (i == commentsMap.end())
|
if (i == commentsMap.end())
|
||||||
i = commentsMap.find("##" + settingRegex.cap(1) + "=" + settingRegex.cap(2));
|
i = commentsMap.find("##" + match.captured(1) + "=" + match.captured(2));
|
||||||
|
|
||||||
if (i != commentsMap.end())
|
if (i != commentsMap.end())
|
||||||
{
|
{
|
||||||
@ -440,7 +446,7 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
|
|||||||
auto i = commentsMap.begin();
|
auto i = commentsMap.begin();
|
||||||
for (; i != commentsMap.end(); ++i)
|
for (; i != commentsMap.end(); ++i)
|
||||||
{
|
{
|
||||||
if (i->first.contains(QRegExp("^\\s*content\\s*=")))
|
if (i->first.contains(QRegularExpression("^\\s*content\\s*=")))
|
||||||
{
|
{
|
||||||
std::vector<QString> cLines = i->second;
|
std::vector<QString> cLines = i->second;
|
||||||
for (const auto& cLine : cLines)
|
for (const auto& cLine : cLines)
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
#include "launchersettings.hpp"
|
#include "launchersettings.hpp"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QMultiMap>
|
#include <QMultiMap>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include <components/files/qtconversion.hpp>
|
#include <components/files/qtconversion.hpp>
|
||||||
|
|
||||||
const char Config::LauncherSettings::sCurrentContentListKey[] = "Profiles/currentprofile";
|
const char Config::LauncherSettings::sCurrentContentListKey[] = "Profiles/currentprofile";
|
||||||
@ -21,16 +20,16 @@ QStringList Config::LauncherSettings::subKeys(const QString& key)
|
|||||||
QMultiMap<QString, QString> settings = SettingsBase::getSettings();
|
QMultiMap<QString, QString> settings = SettingsBase::getSettings();
|
||||||
QStringList keys = settings.uniqueKeys();
|
QStringList keys = settings.uniqueKeys();
|
||||||
|
|
||||||
QRegExp keyRe("(.+)/");
|
QRegularExpression keyRe("(.+)/");
|
||||||
|
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
for (const QString& currentKey : keys)
|
for (const QString& currentKey : keys)
|
||||||
{
|
{
|
||||||
|
QRegularExpressionMatch match = keyRe.match(currentKey);
|
||||||
if (keyRe.indexIn(currentKey) != -1)
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
QString prefixedKey = keyRe.cap(1);
|
QString prefixedKey = match.captured(1);
|
||||||
|
|
||||||
if (prefixedKey.startsWith(key))
|
if (prefixedKey.startsWith(key))
|
||||||
{
|
{
|
||||||
@ -48,7 +47,7 @@ QStringList Config::LauncherSettings::subKeys(const QString& key)
|
|||||||
bool Config::LauncherSettings::writeFile(QTextStream& stream)
|
bool Config::LauncherSettings::writeFile(QTextStream& stream)
|
||||||
{
|
{
|
||||||
QString sectionPrefix;
|
QString sectionPrefix;
|
||||||
QRegExp sectionRe("([^/]+)/(.+)$");
|
QRegularExpression sectionRe(QRegularExpression::anchoredPattern("([^/]+)/(.+)$"));
|
||||||
QMultiMap<QString, QString> settings = SettingsBase::getSettings();
|
QMultiMap<QString, QString> settings = SettingsBase::getSettings();
|
||||||
|
|
||||||
QMapIterator<QString, QString> i(settings);
|
QMapIterator<QString, QString> i(settings);
|
||||||
@ -61,10 +60,11 @@ bool Config::LauncherSettings::writeFile(QTextStream& stream)
|
|||||||
QString prefix;
|
QString prefix;
|
||||||
QString key;
|
QString key;
|
||||||
|
|
||||||
if (sectionRe.exactMatch(i.key()))
|
QRegularExpressionMatch match = sectionRe.match(i.key());
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
prefix = sectionRe.cap(1);
|
prefix = match.captured(1);
|
||||||
key = sectionRe.cap(2);
|
key = match.captured(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get rid of legacy settings
|
// Get rid of legacy settings
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef SETTINGSBASE_HPP
|
#ifndef SETTINGSBASE_HPP
|
||||||
#define SETTINGSBASE_HPP
|
#define SETTINGSBASE_HPP
|
||||||
|
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
@ -42,8 +42,8 @@ namespace Config
|
|||||||
|
|
||||||
QString sectionPrefix;
|
QString sectionPrefix;
|
||||||
|
|
||||||
QRegExp sectionRe("^\\[([^]]+)\\]");
|
QRegularExpression sectionRe(QRegularExpression::anchoredPattern("^\\[([^]]+)\\]"));
|
||||||
QRegExp keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
QRegularExpression keyRe("^([^=]+)\\s*=\\s*(.+)$");
|
||||||
|
|
||||||
while (!stream.atEnd())
|
while (!stream.atEnd())
|
||||||
{
|
{
|
||||||
@ -52,18 +52,19 @@ namespace Config
|
|||||||
if (line.isEmpty() || line.startsWith("#"))
|
if (line.isEmpty() || line.startsWith("#"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (sectionRe.exactMatch(line))
|
QRegularExpressionMatch sectionMatch = sectionRe.match(line);
|
||||||
|
if (sectionMatch.hasMatch())
|
||||||
{
|
{
|
||||||
sectionPrefix = sectionRe.cap(1);
|
sectionPrefix = sectionMatch.captured(1);
|
||||||
sectionPrefix.append("/");
|
sectionPrefix.append("/");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyRe.indexIn(line) != -1)
|
QRegularExpressionMatch match = keyRe.match(line);
|
||||||
|
if (match.hasMatch())
|
||||||
{
|
{
|
||||||
|
QString key = match.captured(1).trimmed();
|
||||||
QString key = keyRe.cap(1).trimmed();
|
QString value = match.captured(2).trimmed();
|
||||||
QString value = keyRe.cap(2).trimmed();
|
|
||||||
|
|
||||||
if (!sectionPrefix.isEmpty())
|
if (!sectionPrefix.isEmpty())
|
||||||
key.prepend(sectionPrefix);
|
key.prepend(sectionPrefix);
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
ContentSelectorView::ComboBox::ComboBox(QWidget* parent)
|
ContentSelectorView::ComboBox::ComboBox(QWidget* parent)
|
||||||
: QComboBox(parent)
|
: QComboBox(parent)
|
||||||
{
|
{
|
||||||
mValidator = new QRegExpValidator(QRegExp("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
mValidator
|
||||||
|
= new QRegularExpressionValidator(QRegularExpression("^[a-zA-Z0-9_]*$"), this); // Alpha-numeric + underscore
|
||||||
setValidator(mValidator);
|
setValidator(mValidator);
|
||||||
setEditable(true);
|
setEditable(true);
|
||||||
setCompleter(nullptr);
|
setCompleter(nullptr);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
class QRegExpValidator;
|
class QRegularExpressionValidator;
|
||||||
|
|
||||||
namespace ContentSelectorView
|
namespace ContentSelectorView
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ namespace ContentSelectorView
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent*) override;
|
void paintEvent(QPaintEvent*) override;
|
||||||
QRegExpValidator* mValidator;
|
QRegularExpressionValidator* mValidator;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ void ContentSelectorView::ContentSelector::buildAddonView()
|
|||||||
ui.addonView->setVisible(true);
|
ui.addonView->setVisible(true);
|
||||||
|
|
||||||
mAddonProxyModel = new AddOnProxyModel(this);
|
mAddonProxyModel = new AddOnProxyModel(this);
|
||||||
mAddonProxyModel->setFilterRegExp(searchFilter()->text());
|
mAddonProxyModel->setFilterRegularExpression(searchFilter()->text());
|
||||||
mAddonProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
mAddonProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
mAddonProxyModel->setDynamicSortFilter(true);
|
mAddonProxyModel->setDynamicSortFilter(true);
|
||||||
mAddonProxyModel->setSourceModel(mContentModel);
|
mAddonProxyModel->setSourceModel(mContentModel);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user