QLatin1String: add startsWith()/endsWith()
[ChangeLog][QtCore][QLatin1String] Added startsWith(), endsWith(). Change-Id: I7f75a5a1f0409f4b9d3e41b73f4fb5d137572b09 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru> Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
d21a147e2b
commit
3644e722c2
|
|
@ -8888,6 +8888,46 @@ QString &QString::setRawData(const QChar *unicode, int size)
|
|||
\sa front(), at(), operator[]()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::startsWith(QStringView str, Qt::CaseSensitivity cs) const
|
||||
\since 5.10
|
||||
\fn bool QLatin1String::startsWith(QLatin1String l1, Qt::CaseSensitivity cs) const
|
||||
\since 5.10
|
||||
\fn bool QLatin1String::startsWith(QChar ch) const
|
||||
\since 5.10
|
||||
\fn bool QLatin1String::startsWith(QChar ch, Qt::CaseSensitivity cs) const
|
||||
\since 5.10
|
||||
|
||||
Returns \c true if this Latin-1 string starts with string-view \a str,
|
||||
Latin-1 string \a l1, or character \a ch, respectively;
|
||||
otherwise returns \c false.
|
||||
|
||||
If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive;
|
||||
otherwise the search is case-insensitive.
|
||||
|
||||
\sa endsWith(), qStartsWith()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn bool QLatin1String::endsWith(QStringView str, Qt::CaseSensitivity cs) const
|
||||
\since 5.10
|
||||
\fn bool QLatin1String::endsWith(QLatin1String l1, Qt::CaseSensitivity cs) const
|
||||
\since 5.10
|
||||
\fn bool QLatin1String::endsWith(QChar ch) const
|
||||
\since 5.10
|
||||
\fn bool QLatin1String::endsWith(QChar ch, Qt::CaseSensitivity cs) const
|
||||
\since 5.10
|
||||
|
||||
Returns \c true if this Latin-1 string ends with string-view \a str,
|
||||
Latin-1 string \a l1, or character \a ch, respectively;
|
||||
otherwise returns \c false.
|
||||
|
||||
If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive;
|
||||
otherwise the search is case-insensitive.
|
||||
|
||||
\sa startsWith(), qEndsWith()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn QLatin1String::const_iterator QLatin1String::begin() const
|
||||
\since 5.10
|
||||
|
|
|
|||
|
|
@ -110,6 +110,24 @@ public:
|
|||
Q_DECL_CONSTEXPR QLatin1Char front() const Q_REQUIRED_RESULT { return at(0); }
|
||||
Q_DECL_CONSTEXPR QLatin1Char back() const Q_REQUIRED_RESULT { return at(size() - 1); }
|
||||
|
||||
Q_REQUIRED_RESULT bool startsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
||||
{ return qStartsWith(*this, s, cs); }
|
||||
Q_REQUIRED_RESULT bool startsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
||||
{ return qStartsWith(*this, s, cs); }
|
||||
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool startsWith(QChar c) const Q_DECL_NOTHROW
|
||||
{ return !isEmpty() && front() == c; }
|
||||
Q_REQUIRED_RESULT inline bool startsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
|
||||
{ return qStartsWith(*this, QStringView(&c, 1), cs); }
|
||||
|
||||
Q_REQUIRED_RESULT bool endsWith(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
||||
{ return qEndsWith(*this, s, cs); }
|
||||
Q_REQUIRED_RESULT bool endsWith(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Q_DECL_NOTHROW
|
||||
{ return qEndsWith(*this, s, cs); }
|
||||
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool endsWith(QChar c) const Q_DECL_NOTHROW
|
||||
{ return !isEmpty() && back() == c; }
|
||||
Q_REQUIRED_RESULT inline bool endsWith(QChar c, Qt::CaseSensitivity cs) const Q_DECL_NOTHROW
|
||||
{ return qEndsWith(*this, QStringView(&c, 1), cs); }
|
||||
|
||||
using value_type = const char;
|
||||
using reference = value_type&;
|
||||
using const_reference = reference;
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ private:
|
|||
template <typename Haystack, typename Needle> void endsWith_impl() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
// test all combinations of {QString, QStringRef, QStringView} x {QString, QStringRef, QStringView, QLatin1String, QChar}:
|
||||
// test all combinations of {QString, QStringRef, QStringView, QLatin1String} 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(); }
|
||||
|
|
@ -223,6 +223,17 @@ private Q_SLOTS:
|
|||
void startsWith_QStringView_QChar_data() { startsWith_data(false); }
|
||||
void startsWith_QStringView_QChar() { startsWith_impl<QStringView, QChar>(); }
|
||||
|
||||
void startsWith_QLatin1String_QString_data() { startsWith_data(); }
|
||||
void startsWith_QLatin1String_QString() { startsWith_impl<QLatin1String, QString>(); }
|
||||
void startsWith_QLatin1String_QStringRef_data() { startsWith_data(); }
|
||||
void startsWith_QLatin1String_QStringRef() { startsWith_impl<QLatin1String, QStringRef>(); }
|
||||
void startsWith_QLatin1String_QStringView_data() { startsWith_data(); }
|
||||
void startsWith_QLatin1String_QStringView() { startsWith_impl<QLatin1String, QStringView>(); }
|
||||
void startsWith_QLatin1String_QLatin1String_data() { startsWith_data(); }
|
||||
void startsWith_QLatin1String_QLatin1String() { startsWith_impl<QLatin1String, QLatin1String>(); }
|
||||
void startsWith_QLatin1String_QChar_data() { startsWith_data(false); }
|
||||
void startsWith_QLatin1String_QChar() { startsWith_impl<QLatin1String, QChar>(); }
|
||||
|
||||
void endsWith_QString_QString_data() { endsWith_data(); }
|
||||
void endsWith_QString_QString() { endsWith_impl<QString, QString>(); }
|
||||
void endsWith_QString_QStringRef_data() { endsWith_data(); }
|
||||
|
|
@ -256,6 +267,17 @@ private Q_SLOTS:
|
|||
void endsWith_QStringView_QChar_data() { endsWith_data(false); }
|
||||
void endsWith_QStringView_QChar() { endsWith_impl<QStringView, QChar>(); }
|
||||
|
||||
void endsWith_QLatin1String_QString_data() { endsWith_data(); }
|
||||
void endsWith_QLatin1String_QString() { endsWith_impl<QLatin1String, QString>(); }
|
||||
void endsWith_QLatin1String_QStringRef_data() { endsWith_data(); }
|
||||
void endsWith_QLatin1String_QStringRef() { endsWith_impl<QLatin1String, QStringRef>(); }
|
||||
void endsWith_QLatin1String_QStringView_data() { endsWith_data(); }
|
||||
void endsWith_QLatin1String_QStringView() { endsWith_impl<QLatin1String, QStringView>(); }
|
||||
void endsWith_QLatin1String_QLatin1String_data() { endsWith_data(); }
|
||||
void endsWith_QLatin1String_QLatin1String() { endsWith_impl<QLatin1String, QLatin1String>(); }
|
||||
void endsWith_QLatin1String_QChar_data() { endsWith_data(false); }
|
||||
void endsWith_QLatin1String_QChar() { endsWith_impl<QLatin1String, QChar>(); }
|
||||
|
||||
private:
|
||||
void mid_data();
|
||||
template <typename String> void mid_impl();
|
||||
|
|
|
|||
Loading…
Reference in New Issue