summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qstring.cpp46
-rw-r--r--src/corelib/tools/qstring.h21
-rw-r--r--tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp10
3 files changed, 74 insertions, 3 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index d6a87378ee..32847933c6 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -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,8 +4589,24 @@ 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()
@@ -10665,6 +10697,13 @@ bool QStringRef::startsWith(QLatin1String str, Qt::CaseSensitivity cs) const
}
/*!
+ \fn bool QStringRef::startsWith(QStringView str, Qt::CaseSensitivity cs) const
+ \since 5.10
+ \overload startsWith()
+ \sa QString::startsWith(), endsWith()
+*/
+
+/*!
\since 4.8
\overload startsWith()
\sa QString::startsWith(), endsWith()
@@ -10734,6 +10773,13 @@ bool QStringRef::endsWith(QLatin1String str, Qt::CaseSensitivity cs) const
}
/*!
+ \fn bool QStringRef::endsWith(QStringView str, Qt::CaseSensitivity cs) const
+ \since 5.10
+ \overload endsWith()
+ \sa QString::endsWith(), startsWith()
+*/
+
+/*!
\since 4.8
\overload endsWith()
\sa QString::endsWith(), endsWith()
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 2b47883598..108021cfc4 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -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);
diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
index 8e5848a592..890cca7a55 100644
--- a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
+++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -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); }