diff --git a/src/corelib/text/qstringlist.cpp b/src/corelib/text/qstringlist.cpp index 4ff6d56603..eddd392029 100644 --- a/src/corelib/text/qstringlist.cpp +++ b/src/corelib/text/qstringlist.cpp @@ -286,6 +286,18 @@ QStringList QtPrivate::QStringList_filter(const QStringList &that, const QString return res; } +/*! + \fn QStringList QStringList::filter(QLatin1StringView str, Qt::CaseSensitivity cs) const + \since 6.7 + \overload +*/ + +QStringList QtPrivate::QStringList_filter(const QStringList &that, QLatin1StringView needle, + Qt::CaseSensitivity cs) +{ + return filter_helper(that, needle, cs); +} + template static bool stringList_contains(const QStringList &stringList, const T &str, Qt::CaseSensitivity cs) { diff --git a/src/corelib/text/qstringlist.h b/src/corelib/text/qstringlist.h index 752fc58865..13a93f505a 100644 --- a/src/corelib/text/qstringlist.h +++ b/src/corelib/text/qstringlist.h @@ -30,6 +30,8 @@ namespace QtPrivate { Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1StringView sep); QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str, Qt::CaseSensitivity cs); + Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that, QLatin1StringView needle, + Qt::CaseSensitivity cs); Q_CORE_EXPORT QStringList QStringList_filter(const QStringList &that, const QStringMatcher &matcher); @@ -88,6 +90,8 @@ public: QStringList filter(const QStringMatcher &matcher) const { return QtPrivate::QStringList_filter(*self(), matcher); } + QStringList filter(QLatin1StringView needle, Qt::CaseSensitivity cs = Qt::CaseSensitive) const + { return QtPrivate::QStringList_filter(*self(), needle, cs); } inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const { return QtPrivate::QStringList_filter(self(), str, cs); } inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive) diff --git a/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp index 233f642dbf..e511d63be1 100644 --- a/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/text/qstringlist/tst_qstringlist.cpp @@ -169,6 +169,7 @@ void tst_QStringList::filter() const QStringList expected{u"Bill Gates"_s, u"Bill Clinton"_s}; QCOMPARE(list.filter(u"Bill"_s), expected); QCOMPARE(list.filter(u"Bill"), expected); + QCOMPARE(list.filter("Bill"_L1), expected); QCOMPARE(list.filter(QRegularExpression(u"[i]ll"_s)), expected); QCOMPARE(list.filter(QStringMatcher(u"Bill")), expected); } @@ -177,6 +178,7 @@ void tst_QStringList::filter() const QStringList expected = {u"Bill Gates"_s, u"Bill Clinton"_s, u"bIll"_s}; QCOMPARE(list.filter(u"bill"_s, Qt::CaseInsensitive), expected); QCOMPARE(list.filter(u"bill", Qt::CaseInsensitive), expected); + QCOMPARE(list.filter("bill"_L1, Qt::CaseInsensitive), expected); QCOMPARE(list.filter(QRegularExpression(u"[i]ll"_s, QRegularExpression::CaseInsensitiveOption)), expected); QCOMPARE(list.filter(QStringMatcher(u"Bill", Qt::CaseInsensitive)), expected);