QStringList: add filter(QL1SV) overload
[ChangeLog][QtCore][QStringList] Added filter(QLatin1StringView) overload, which is more optimized when searching for a Latin-1 string literal as no conversion to QString is necessary. Task-number: QTBUG-116918 Change-Id: Ieb92f4cfd545b070258dbc5c701ddfb2e6f3fc64 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3dffd5aa0b
commit
c205f05128
@ -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<typename T>
|
||||
static bool stringList_contains(const QStringList &stringList, const T &str, Qt::CaseSensitivity cs)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user