diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-04-24 11:26:25 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-04-28 16:41:08 +0000 |
commit | cac2fc81b75f60d84b850fec81b432b020e89ed3 (patch) | |
tree | 7619b7210ac5e14bf2b2cbbfe322777427756287 /src/corelib/tools/qstring.cpp | |
parent | 99d809bd75582180a3a8178287862262024f8f33 (diff) |
Long live qStartsWith()/qEndsWith()!
Following the established pattern of implementing non-mutating string
algorithms as free functions over views with a public qFoo() and a
static qt_foo() split, add qStartsWith() and qEndsWith(), calling the
existing qt_{starts,ends}_with_impl() templates.
[ChangeLog][QtCore][QStringAlgorithms] Added qStartsWith(),
qEndsWith().
Change-Id: Ic95c2a9c13883a99f1a96319083fb249f20de5f1
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Anton Kudryavtsev <antkudr@mail.ru>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Martin Smith <martin.smith@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index a46ff1e881..d6a87378ee 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -10907,6 +10907,46 @@ static inline bool qt_starts_with(QStringView haystack, QChar needle, Qt::CaseSe : foldCase(haystack.front()) == foldCase(needle)); } +/*! + \fn bool qStartsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) + \since 5.10 + \fn bool qStartsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \since 5.10 + \fn bool qStartsWith(QLatin1String haystack, QStringview needle, Qt::CaseSensitivity cs) + \since 5.10 + \fn bool qStartsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \since 5.10 + \relates QStringView + + Returns \c true if \a haystack starts with \a needle, + otherwise returns \c false. + + If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; + otherwise the search is case-insensitive. + + \sa qEndsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() +*/ + +bool qStartsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_starts_with_impl(haystack, needle, cs); +} + +bool qStartsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_starts_with_impl(haystack, needle, cs); +} + +bool qStartsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_starts_with_impl(haystack, needle, cs); +} + +bool qStartsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_starts_with_impl(haystack, needle, cs); +} + template <typename Haystack, typename Needle> bool qt_ends_with_impl(Haystack haystack, Needle needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW { @@ -10940,6 +10980,46 @@ static inline bool qt_ends_with(QStringView haystack, QChar needle, Qt::CaseSens } /*! + \fn bool qEndsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) + \since 5.10 + \fn bool qEndsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \since 5.10 + \fn bool qEndsWith(QLatin1String haystack, QStringview needle, Qt::CaseSensitivity cs) + \since 5.10 + \fn bool qEndsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) + \since 5.10 + \relates QStringView + + Returns \c true if \a haystack ends with \a needle, + otherwise returns \c false. + + If \a cs is Qt::CaseSensitive (the default), the search is case-sensitive; + otherwise the search is case-insensitive. + + \sa qEndsWith(), QString::endsWith(), QStringView::endsWith(), QLatin1String::endsWith() +*/ + +bool qEndsWith(QStringView haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_ends_with_impl(haystack, needle, cs); +} + +bool qEndsWith(QStringView haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_ends_with_impl(haystack, needle, cs); +} + +bool qEndsWith(QLatin1String haystack, QStringView needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_ends_with_impl(haystack, needle, cs); +} + +bool qEndsWith(QLatin1String haystack, QLatin1String needle, Qt::CaseSensitivity cs) Q_DECL_NOTHROW +{ + return qt_ends_with_impl(haystack, needle, cs); +} + +/*! \since 4.8 Returns a Latin-1 representation of the string as a QByteArray. |