QString/Ref: add startsWith/endsWith(QStringView) overloads

[ChangeLog][QtCore][QString/QStringRef] Added startsWith(), endsWith()
overloads taking QStringView.

Change-Id: Ice6332492d19fd7477d5ac43ecbf6b70175b23ca
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Marc Mutz 2017-04-24 11:31:00 +02:00
parent cac2fc81b7
commit 5f3d6ce570
3 changed files with 74 additions and 3 deletions

View File

@ -4536,6 +4536,7 @@ QString QString::mid(int position, int n) const
\sa endsWith(), left(), right(), mid(), chop(), truncate()
*/
#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns \c true if the string starts with \a s; otherwise returns
\c false.
@ -4551,6 +4552,7 @@ bool QString::startsWith(const QString& s, Qt::CaseSensitivity cs) const
{
return qt_starts_with(*this, s, cs);
}
#endif
/*!
\overload startsWith()
@ -4571,6 +4573,7 @@ bool QString::startsWith(QChar c, Qt::CaseSensitivity cs) const
return qt_starts_with(*this, c, cs);
}
#if QT_STRINGVIEW_LEVEL < 2
/*!
\since 4.8
\overload
@ -4586,7 +4589,23 @@ bool QString::startsWith(const QStringRef &s, Qt::CaseSensitivity cs) const
{
return qt_starts_with(*this, s, cs);
}
#endif
/*!
\fn bool QString::startsWith(QStringView str, Qt::CaseSensitivity cs) const
\since 5.10
\overload
Returns \c true if the string starts with the string-view \a str;
otherwise returns \c false.
If \a cs is Qt::CaseSensitive (default), the search is case-sensitive;
otherwise the search is case insensitive.
\sa endsWith()
*/
#if QT_STRINGVIEW_LEVEL < 2
/*!
Returns \c true if the string ends with \a s; otherwise returns
\c false.
@ -4618,7 +4637,20 @@ bool QString::endsWith(const QStringRef &s, Qt::CaseSensitivity cs) const
{
return qt_ends_with(*this, s, cs);
}
#endif // QT_STRINGVIEW_LEVEL < 2
/*!
\fn bool QString::endsWith(QStringView str, Qt::CaseSensitivity cs) const
\since 5.10
\overload endsWith()
Returns \c true if the string ends with the string view \a str;
otherwise returns \c false.
If \a cs is Qt::CaseSensitive (default), the search is case
sensitive; otherwise the search is case insensitive.
\sa startsWith()
*/
/*!
\overload endsWith()
@ -10664,6 +10696,13 @@ bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const
return qt_starts_with(*this, str, cs);
}
/*!
\fn bool QStringRef::startsWith(QStringView str, Qt::CaseSensitivity cs) const
\since 5.10
\overload startsWith()
\sa QString::startsWith(), endsWith()
*/
/*!
\since 4.8
\overload startsWith()
@ -10733,6 +10772,13 @@ bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const
return qt_ends_with(*this, str, cs);
}
/*!
\fn bool QStringRef::endsWith(QStringView str, Qt::CaseSensitivity cs) const
\since 5.10
\overload endsWith()
\sa QString::endsWith(), startsWith()
*/
/*!
\since 4.8
\overload endsWith()

View File

@ -355,12 +355,21 @@ public:
Q_REQUIRED_RESULT QStringRef rightRef(int n) const;
Q_REQUIRED_RESULT QStringRef midRef(int position, int n = -1) const;
#if QT_STRINGVIEW_LEVEL < 2
bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool startsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
{ return qStartsWith(*this, s, cs); }
bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_STRINGVIEW_LEVEL < 2
bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool endsWith(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
{ return qEndsWith(*this, s, cs); }
bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
@ -1445,15 +1454,23 @@ public:
bool isRightToLeft() const;
bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
{ return qStartsWith(*this, s, cs); }
bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool startsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_STRINGVIEW_LEVEL < 2
bool startsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool startsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
{ return qEndsWith(*this, s, cs); }
bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool endsWith(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_STRINGVIEW_LEVEL < 2
bool endsWith(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
bool endsWith(const QStringRef &c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
inline QStringRef &operator=(const QString *string);

View File

@ -189,11 +189,13 @@ private:
template <typename Haystack, typename Needle> void endsWith_impl() const;
private Q_SLOTS:
// test all combinations of {QString, QStringRef} x {QString, QStringRef, QLatin1String, QChar}:
// test all combinations of {QString, QStringRef} x {QString, QStringRef, QStringView, QLatin1String, QChar}:
void startsWith_QString_QString_data() { startsWith_data(); }
void startsWith_QString_QString() { startsWith_impl<QString, QString>(); }
void startsWith_QString_QStringRef_data() { startsWith_data(); }
void startsWith_QString_QStringRef() { startsWith_impl<QString, QStringRef>(); }
void startsWith_QString_QStringView_data() { startsWith_data(); }
void startsWith_QString_QStringView() { startsWith_impl<QString, QStringView>(); }
void startsWith_QString_QLatin1String_data() { startsWith_data(); }
void startsWith_QString_QLatin1String() { startsWith_impl<QString, QLatin1String>(); }
void startsWith_QString_QChar_data() { startsWith_data(false); }
@ -203,6 +205,8 @@ private Q_SLOTS:
void startsWith_QStringRef_QString() { startsWith_impl<QStringRef, QString>(); }
void startsWith_QStringRef_QStringRef_data() { startsWith_data(); }
void startsWith_QStringRef_QStringRef() { startsWith_impl<QStringRef, QStringRef>(); }
void startsWith_QStringRef_QStringView_data() { startsWith_data(); }
void startsWith_QStringRef_QStringView() { startsWith_impl<QStringRef, QStringView>(); }
void startsWith_QStringRef_QLatin1String_data() { startsWith_data(); }
void startsWith_QStringRef_QLatin1String() { startsWith_impl<QStringRef, QLatin1String>(); }
void startsWith_QStringRef_QChar_data() { startsWith_data(false); }
@ -212,6 +216,8 @@ private Q_SLOTS:
void endsWith_QString_QString() { endsWith_impl<QString, QString>(); }
void endsWith_QString_QStringRef_data() { endsWith_data(); }
void endsWith_QString_QStringRef() { endsWith_impl<QString, QStringRef>(); }
void endsWith_QString_QStringView_data() { endsWith_data(); }
void endsWith_QString_QStringView() { endsWith_impl<QString, QStringView>(); }
void endsWith_QString_QLatin1String_data() { endsWith_data(); }
void endsWith_QString_QLatin1String() { endsWith_impl<QString, QLatin1String>(); }
void endsWith_QString_QChar_data() { endsWith_data(false); }
@ -221,6 +227,8 @@ private Q_SLOTS:
void endsWith_QStringRef_QString() { endsWith_impl<QStringRef, QString>(); }
void endsWith_QStringRef_QStringRef_data() { endsWith_data(); }
void endsWith_QStringRef_QStringRef() { endsWith_impl<QStringRef, QStringRef>(); }
void endsWith_QStringRef_QStringView_data() { endsWith_data(); }
void endsWith_QStringRef_QStringView() { endsWith_impl<QStringRef, QStringView>(); }
void endsWith_QStringRef_QLatin1String_data() { endsWith_data(); }
void endsWith_QStringRef_QLatin1String() { endsWith_impl<QStringRef, QLatin1String>(); }
void endsWith_QStringRef_QChar_data() { endsWith_data(false); }