QStringMatcher: add a method that returns a string view of the pattern
The existing pattern() method always returns a QString, which means that if the matcher was constructed using a QStringView, pattern() would uncoditionally convert it to a QString. This is useful to check if a match is exact: auto pattern = matcher.patternView(); if (pattern.size() == needle.size() && matcher.indexIn(needle) == 0) .... This may be needed for a later change in QStringList::contains(); regardless of that, this change makes sense on its own. Change-Id: I49018551dd22a8f88cf6b9f878a5166902a26f58 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
90532e0b01
commit
341854a4f3
@ -242,6 +242,15 @@ QString QStringMatcher::pattern() const
|
|||||||
return q_sv.toString();
|
return q_sv.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn QStringView QStringMatcher::patternView() const noexcept
|
||||||
|
\since 6.7
|
||||||
|
|
||||||
|
Returns a string view of the pattern that this string matcher will search for.
|
||||||
|
|
||||||
|
\sa setPattern()
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets the case sensitivity setting of this string matcher to \a
|
Sets the case sensitivity setting of this string matcher to \a
|
||||||
cs.
|
cs.
|
||||||
|
@ -40,6 +40,9 @@ public:
|
|||||||
{ return indexIn(QStringView(str, length), from); }
|
{ return indexIn(QStringView(str, length), from); }
|
||||||
qsizetype indexIn(QStringView str, qsizetype from = 0) const;
|
qsizetype indexIn(QStringView str, qsizetype from = 0) const;
|
||||||
QString pattern() const;
|
QString pattern() const;
|
||||||
|
QStringView patternView() const noexcept
|
||||||
|
{ return q_sv; }
|
||||||
|
|
||||||
inline Qt::CaseSensitivity caseSensitivity() const { return q_cs; }
|
inline Qt::CaseSensitivity caseSensitivity() const { return q_cs; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -24,6 +24,7 @@ void tst_QStringMatcher::qstringmatcher()
|
|||||||
QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive);
|
QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive);
|
||||||
QCOMPARE(matcher.indexIn("foo", 1), 1);
|
QCOMPARE(matcher.indexIn("foo", 1), 1);
|
||||||
QCOMPARE(matcher.pattern(), QString());
|
QCOMPARE(matcher.pattern(), QString());
|
||||||
|
QCOMPARE(matcher.patternView(), QStringView());
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Qt::CaseSensitivity caseSensitivity() const
|
// public Qt::CaseSensitivity caseSensitivity() const
|
||||||
@ -143,6 +144,7 @@ void tst_QStringMatcher::assignOperator()
|
|||||||
|
|
||||||
QStringMatcher m2 = m1;
|
QStringMatcher m2 = m1;
|
||||||
QCOMPARE(m2.pattern(), needle);
|
QCOMPARE(m2.pattern(), needle);
|
||||||
|
QCOMPARE(m2.patternView(), needle);
|
||||||
QCOMPARE(m2.indexIn(hayStack), 3);
|
QCOMPARE(m2.indexIn(hayStack), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user