Use QRE::matchView instead of match when argument is a stringview
The QStringView overload of match will be deprecated in Qt 6.8. As a drive-by, replace a match(view.toString()) with a a matchView; the view lives long enough, so no reason to convert to QString. Also use capturedView instead of captured when working with string-views, and hoist one regex construction out of a loop. As the QML DOM has to build with older Qt versions, condition the use of matchView on Qt being >= 6.4 Fixes: QTBUG-105360 Change-Id: If248d135fd381c6368d446376798a52dec220b40 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
This commit is contained in:
parent
2bd4ee37ff
commit
9c2fd1724c
|
@ -724,7 +724,11 @@ public:
|
||||||
pathFromOwner = comp.addId(idVal, AddOption::KeepExisting, &idPtr);
|
pathFromOwner = comp.addId(idVal, AddOption::KeepExisting, &idPtr);
|
||||||
QRegularExpression idRe(QRegularExpression::anchoredPattern(
|
QRegularExpression idRe(QRegularExpression::anchoredPattern(
|
||||||
QStringLiteral(uR"([[:lower:]][[:lower:][:upper:]0-9_]*)")));
|
QStringLiteral(uR"([[:lower:]][[:lower:][:upper:]0-9_]*)")));
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
auto m = idRe.match(iExp->name);
|
auto m = idRe.match(iExp->name);
|
||||||
|
#else
|
||||||
|
auto m = idRe.matchView(iExp->name);
|
||||||
|
#endif
|
||||||
if (!m.hasMatch()) {
|
if (!m.hasMatch()) {
|
||||||
qmlFile.addError(
|
qmlFile.addError(
|
||||||
myParseErrors()
|
myParseErrors()
|
||||||
|
|
|
@ -203,13 +203,17 @@ Version Version::fromString(QStringView v)
|
||||||
return Version(Latest, Latest);
|
return Version(Latest, Latest);
|
||||||
QRegularExpression r(
|
QRegularExpression r(
|
||||||
QRegularExpression::anchoredPattern(QStringLiteral(uR"(([0-9]*)(?:\.([0-9]*))?)")));
|
QRegularExpression::anchoredPattern(QStringLiteral(uR"(([0-9]*)(?:\.([0-9]*))?)")));
|
||||||
auto m = r.match(v.toString());
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
auto m = r.match(v);
|
||||||
|
#else
|
||||||
|
auto m = r.matchView(v);
|
||||||
|
#endif
|
||||||
if (m.hasMatch()) {
|
if (m.hasMatch()) {
|
||||||
bool ok;
|
bool ok;
|
||||||
int majorV = m.captured(1).toInt(&ok);
|
int majorV = m.capturedView(1).toInt(&ok);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
majorV = Version::Undefined;
|
majorV = Version::Undefined;
|
||||||
int minorV = m.captured(2).toInt(&ok);
|
int minorV = m.capturedView(2).toInt(&ok);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
minorV = Version::Undefined;
|
minorV = Version::Undefined;
|
||||||
return Version(majorV, minorV);
|
return Version(majorV, minorV);
|
||||||
|
|
|
@ -97,14 +97,19 @@ bool FieldFilter::operator()(DomItem &base, const PathEls::PathComponent &c, Dom
|
||||||
|
|
||||||
bool FieldFilter::addFilter(QString fFields)
|
bool FieldFilter::addFilter(QString fFields)
|
||||||
{
|
{
|
||||||
for (const QString &fField : fFields.split(QLatin1Char(','))) {
|
|
||||||
// parses a base filter of the form <op><typeName>:<fieldName> or <op><fieldName>
|
// parses a base filter of the form <op><typeName>:<fieldName> or <op><fieldName>
|
||||||
// as described in this class documentation
|
// as described in this class documentation
|
||||||
QRegularExpression fieldRe(QRegularExpression::anchoredPattern(QStringLiteral(
|
QRegularExpression fieldRe(QRegularExpression::anchoredPattern(QStringLiteral(
|
||||||
uR"((?<op>[-+])?(?:(?<type>[a-zA-Z0-9_]*):)?(?<field>[a-zA-Z0-9_]*))")));
|
uR"((?<op>[-+])?(?:(?<type>[a-zA-Z0-9_]*):)?(?<field>[a-zA-Z0-9_]*))")));
|
||||||
|
for (const QString &fField : fFields.split(QLatin1Char(','))) {
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
QRegularExpressionMatch m = fieldRe.match(fField);
|
QRegularExpressionMatch m = fieldRe.match(fField);
|
||||||
|
#else
|
||||||
|
QRegularExpressionMatch m = fieldRe.matchView(fField);
|
||||||
|
#endif
|
||||||
if (m.hasMatch()) {
|
if (m.hasMatch()) {
|
||||||
if (m.captured(u"op") == u"+") {
|
if (m.capturedView(u"op") == u"+") {
|
||||||
m_fieldFilterRemove.remove(m.captured(u"type"), m.captured(u"field"));
|
m_fieldFilterRemove.remove(m.captured(u"type"), m.captured(u"field"));
|
||||||
m_fieldFilterAdd.insert(m.captured(u"type"), m.captured(u"field"));
|
m_fieldFilterAdd.insert(m.captured(u"type"), m.captured(u"field"));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1680,7 +1680,12 @@ public:
|
||||||
CppTypeInfo res;
|
CppTypeInfo res;
|
||||||
QRegularExpression reTarget = QRegularExpression(QRegularExpression::anchoredPattern(
|
QRegularExpression reTarget = QRegularExpression(QRegularExpression::anchoredPattern(
|
||||||
uR"(QList<(?<list>[a-zA-Z_0-9:]+) *(?<listPtr>\*?)>|QMap< *(?<mapKey>[a-zA-Z_0-9:]+) *, *(?<mapValue>[a-zA-Z_0-9:]+) *(?<mapPtr>\*?)>|(?<baseType>[a-zA-Z_0-9:]+) *(?<ptr>\*?))"));
|
uR"(QList<(?<list>[a-zA-Z_0-9:]+) *(?<listPtr>\*?)>|QMap< *(?<mapKey>[a-zA-Z_0-9:]+) *, *(?<mapValue>[a-zA-Z_0-9:]+) *(?<mapPtr>\*?)>|(?<baseType>[a-zA-Z_0-9:]+) *(?<ptr>\*?))"));
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
QRegularExpressionMatch m = reTarget.match(target);
|
QRegularExpressionMatch m = reTarget.match(target);
|
||||||
|
#else
|
||||||
|
QRegularExpressionMatch m = reTarget.matchView(target);
|
||||||
|
#endif
|
||||||
if (!m.hasMatch()) {
|
if (!m.hasMatch()) {
|
||||||
DomItem::myResolveErrors()
|
DomItem::myResolveErrors()
|
||||||
.error(tr("Unexpected complex CppType %1").arg(target))
|
.error(tr("Unexpected complex CppType %1").arg(target))
|
||||||
|
|
|
@ -137,13 +137,23 @@ QString LineWriter::eolToWrite() const
|
||||||
return QStringLiteral(u"\n");
|
return QStringLiteral(u"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename String, typename ...Args>
|
||||||
|
static QRegularExpressionMatch matchHelper(QRegularExpression &re, String &&s, Args &&...args)
|
||||||
|
{
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
|
||||||
|
return re.match(s, args...);
|
||||||
|
#else
|
||||||
|
return re.matchView(s, args...);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
LineWriter &LineWriter::write(QStringView v, TextAddType tAdd)
|
LineWriter &LineWriter::write(QStringView v, TextAddType tAdd)
|
||||||
{
|
{
|
||||||
QString eol;
|
QString eol;
|
||||||
// split multiple lines
|
// split multiple lines
|
||||||
static QRegularExpression eolRe(QLatin1String(
|
static QRegularExpression eolRe(QLatin1String(
|
||||||
"(\r?\n|\r)")); // does not support split of \r and \n for windows style line endings
|
"(\r?\n|\r)")); // does not support split of \r and \n for windows style line endings
|
||||||
QRegularExpressionMatch m = eolRe.match(v);
|
QRegularExpressionMatch m = matchHelper(eolRe, v);
|
||||||
if (m.hasMatch()) {
|
if (m.hasMatch()) {
|
||||||
// add line by line
|
// add line by line
|
||||||
auto i = m.capturedStart(1);
|
auto i = m.capturedStart(1);
|
||||||
|
@ -153,11 +163,11 @@ LineWriter &LineWriter::write(QStringView v, TextAddType tAdd)
|
||||||
// because we cannot have already opened or closed a PendingSourceLocation
|
// because we cannot have already opened or closed a PendingSourceLocation
|
||||||
if (iEnd < v.size()) {
|
if (iEnd < v.size()) {
|
||||||
write(v.mid(0, iEnd));
|
write(v.mid(0, iEnd));
|
||||||
m = eolRe.match(v, iEnd);
|
m = matchHelper(eolRe, v, iEnd);
|
||||||
while (m.hasMatch()) {
|
while (m.hasMatch()) {
|
||||||
write(v.mid(iEnd, m.capturedEnd(1) - iEnd));
|
write(v.mid(iEnd, m.capturedEnd(1) - iEnd));
|
||||||
iEnd = m.capturedEnd(1);
|
iEnd = m.capturedEnd(1);
|
||||||
m = eolRe.match(v, iEnd);
|
m = matchHelper(eolRe, v, iEnd);
|
||||||
}
|
}
|
||||||
if (iEnd < v.size())
|
if (iEnd < v.size())
|
||||||
write(v.mid(iEnd, v.size() - iEnd));
|
write(v.mid(iEnd, v.size() - iEnd));
|
||||||
|
|
Loading…
Reference in New Issue