diff --git a/src/corelib/text/qstringmatcher.cpp b/src/corelib/text/qstringmatcher.cpp index ac66ec802e..379d555e54 100644 --- a/src/corelib/text/qstringmatcher.cpp +++ b/src/corelib/text/qstringmatcher.cpp @@ -242,6 +242,15 @@ QString QStringMatcher::pattern() const 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 cs. diff --git a/src/corelib/text/qstringmatcher.h b/src/corelib/text/qstringmatcher.h index 581d8931e4..937f17df0a 100644 --- a/src/corelib/text/qstringmatcher.h +++ b/src/corelib/text/qstringmatcher.h @@ -40,6 +40,9 @@ public: { return indexIn(QStringView(str, length), from); } qsizetype indexIn(QStringView str, qsizetype from = 0) const; QString pattern() const; + QStringView patternView() const noexcept + { return q_sv; } + inline Qt::CaseSensitivity caseSensitivity() const { return q_cs; } private: diff --git a/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp b/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp index 6378ed8f5a..4488e5e2c5 100644 --- a/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp +++ b/tests/auto/corelib/text/qstringmatcher/tst_qstringmatcher.cpp @@ -24,6 +24,7 @@ void tst_QStringMatcher::qstringmatcher() QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive); QCOMPARE(matcher.indexIn("foo", 1), 1); QCOMPARE(matcher.pattern(), QString()); + QCOMPARE(matcher.patternView(), QStringView()); } // public Qt::CaseSensitivity caseSensitivity() const @@ -143,6 +144,7 @@ void tst_QStringMatcher::assignOperator() QStringMatcher m2 = m1; QCOMPARE(m2.pattern(), needle); + QCOMPARE(m2.patternView(), needle); QCOMPARE(m2.indexIn(hayStack), 3); }