summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qbytearraymatcher.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-21 18:06:24 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-01-23 09:48:28 +0100
commitcce7e35253aa63191f0211b509784b1dc96d49e5 (patch)
tree6e8067597ec1e61248edf16b53a67254dfd7eca5 /src/corelib/text/qbytearraymatcher.h
parent3d3558dc8f0a1885f416b4650037364f4ef11bd4 (diff)
Q(Static)ByteArrayMatcher: manage indexIn() overloads
Unlike QString and QStringView, QByteArrayView and QByteArray don't overload well. Solve the overload issue the usual way: by making the QByteArray one a Q_WEAK_OVERLOAD. This is trivial for QStaticByteArrayMatcher, which isn't exported, but require QT_REMOVED_SINCE magic for QByteArrayMatcher, which is. The additional const char* overload has shielded us from the worst fall-out so far, it seems, but it makes for a truly horrible overload set: matcher.indexIn(str, 3); Q: Is the 3 here the length of the haystack or the value of the from parameter? A: It depends on decltype(str)! If the (const char*, qsizetype, qsizetype=0) overload is the better match, then 3 limits the haystack's length. If, otoh, the (QByteArray(View), qsizetype) overload is the better match, then it's the value of the from parameter. As if this wasn't bad enough, QByteArray implcitly converts to const char* by default! A follow-up patch will therefore deprecate the (ptr, size) overloads, so we de-inline the QByteArrayView ones to avoid having to touch the implementation once more. Found during 6.3 API review. Pick-to: 6.3 Change-Id: I9640e0bdd298d651511adebcc85f314db9221d34 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/text/qbytearraymatcher.h')
-rw-r--r--src/corelib/text/qbytearraymatcher.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/corelib/text/qbytearraymatcher.h b/src/corelib/text/qbytearraymatcher.h
index 80473c7585..7aa6226b24 100644
--- a/src/corelib/text/qbytearraymatcher.h
+++ b/src/corelib/text/qbytearraymatcher.h
@@ -65,12 +65,15 @@ public:
void setPattern(const QByteArray &pattern);
+#if QT_REMOVED_SINCE(6, 3)
qsizetype indexIn(const QByteArray &ba, qsizetype from = 0) const;
+#else
+ Q_WEAK_OVERLOAD
+ qsizetype indexIn(const QByteArray &ba, qsizetype from = 0) const
+ { return indexIn(QByteArrayView{ba}, from); }
+#endif
qsizetype indexIn(const char *str, qsizetype len, qsizetype from = 0) const;
- qsizetype indexIn(QByteArrayView data, qsizetype from = 0) const
- {
- return indexIn(data.data(), data.size(), from);
- }
+ qsizetype indexIn(QByteArrayView data, qsizetype from = 0) const;
inline QByteArray pattern() const
{
if (q_pattern.isNull())
@@ -162,10 +165,13 @@ public:
m_pattern[i] = patternToMatch[i];
}
+ Q_WEAK_OVERLOAD
qsizetype indexIn(const QByteArray &haystack, qsizetype from = 0) const noexcept
{ return this->indexOfIn(m_pattern, N - 1, haystack.data(), haystack.size(), from); }
qsizetype indexIn(const char *haystack, qsizetype hlen, qsizetype from = 0) const noexcept
{ return this->indexOfIn(m_pattern, N - 1, haystack, hlen, from); }
+ qsizetype indexIn(QByteArrayView haystack, qsizetype from = 0) const noexcept
+ { return this->indexOfIn(m_pattern, N - 1, haystack.data(), haystack.size(), from); }
QByteArray pattern() const { return QByteArray(m_pattern, qsizetype(N - 1)); }
};