summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-05-22 14:12:03 +0200
committerLars Knoll <lars.knoll@qt.io>2020-06-11 15:52:25 +0200
commit8ea11e0cf7f442f687089ffdf54de1f7540cb20b (patch)
treefb9ac9701c73b4708503044795b80bcc3fc7e6b0 /src/corelib/text
parentbf5629af445be8a1cd064a1a096653937b94c9b2 (diff)
Remove most overloads taking a QStringRef from the QString API
Add QStringView overloads where they were missing. This keeps things almost 100% source compatible. Task-number: QTBUG-84319 Change-Id: Ica8ee773b2ce655e9597097786117959e34b236e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/text')
-rw-r--r--src/corelib/text/qstring.cpp125
-rw-r--r--src/corelib/text/qstring.h38
2 files changed, 22 insertions, 141 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index 4083f89cdf..206d495647 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -3789,24 +3789,6 @@ int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
#if QT_STRINGVIEW_LEVEL < 2
/*!
- \since 4.8
-
- \overload indexOf()
-
- Returns the index position of the first occurrence of the string
- reference \a str in this string, searching forward from index
- position \a from. Returns -1 if \a str is not found.
-
- If \a cs is Qt::CaseSensitive (default), the search is case
- sensitive; otherwise the search is case insensitive.
-*/
-int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const
-{
- // ### Qt6: qsizetype
- return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs));
-}
-
-/*!
Returns the index position of the last occurrence of the string \a
str in this string, searching backward from index position \a
from. If \a from is -1 (default), the search starts at the last
@@ -3867,29 +3849,6 @@ int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
return int(qLastIndexOf(QStringView(*this), ch, from, cs));
}
-#if QT_STRINGVIEW_LEVEL < 2
-/*!
- \since 4.8
- \overload lastIndexOf()
-
- Returns the index position of the last occurrence of the string
- reference \a str in this string, searching backward from index
- position \a from. If \a from is -1 (default), the search starts at
- the last character; if \a from is -2, at the next to last character
- and so on. Returns -1 if \a str is not found.
-
- If \a cs is Qt::CaseSensitive (default), the search is case
- sensitive; otherwise the search is case insensitive.
-
- \sa indexOf(), contains(), count()
-*/
-int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const
-{
- // ### Qt6: qsizetype
- return int(QtPrivate::lastIndexOf(*this, from, str, cs));
-}
-#endif // QT_STRINGVIEW_LEVEL < 2
-
/*!
\fn int QString::lastIndexOf(QStringView str, int from, Qt::CaseSensitivity cs) const
\since 5.14
@@ -4080,7 +4039,7 @@ int QString::count(QChar ch, Qt::CaseSensitivity cs) const
}
/*!
- \since 4.8
+ \since 6.0
\overload count()
Returns the number of (potentially overlapping) occurrences of the
string reference \a str in this string.
@@ -4090,10 +4049,10 @@ int QString::count(QChar ch, Qt::CaseSensitivity cs) const
\sa contains(), indexOf()
*/
-int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const
+int QString::count(QStringView str, Qt::CaseSensitivity cs) const
{
// ### Qt6: qsizetype
- return int(QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs));
+ return int(QtPrivate::count(*this, str, cs));
}
#if QT_STRINGVIEW_LEVEL < 2
@@ -4705,24 +4664,6 @@ 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
- Returns \c true if the string starts with the string reference \a s;
- otherwise returns \c false.
-
- If \a cs is Qt::CaseSensitive (default), the search is case
- sensitive; otherwise the search is case insensitive.
-
- \sa endsWith()
-*/
-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
@@ -4753,22 +4694,6 @@ bool QString::endsWith(const QString &s, Qt::CaseSensitivity cs) const
{
return qt_ends_with(*this, s, cs);
}
-
-/*!
- \since 4.8
- \overload endsWith()
- Returns \c true if the string ends with the string reference \a s;
- otherwise returns \c false.
-
- If \a cs is Qt::CaseSensitive (default), the search is case
- sensitive; otherwise the search is case insensitive.
-
- \sa startsWith()
-*/
-bool QString::endsWith(const QStringRef &s, Qt::CaseSensitivity cs) const
-{
- return qt_ends_with(*this, s, cs);
-}
#endif // QT_STRINGVIEW_LEVEL < 2
/*!
@@ -5880,17 +5805,6 @@ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const noexcept
return qt_compare_strings(*this, other, cs);
}
-#if QT_STRINGVIEW_LEVEL < 2
-/*!
- \fn int QString::compare(const QStringRef &ref, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
- \overload compare()
-
- Compares the string reference, \a ref, with the string and returns
- an integer less than, equal to, or greater than zero if the string
- is less than, equal to, or greater than \a ref.
-*/
-#endif
-
/*!
\internal
\since 5.0
@@ -5912,7 +5826,12 @@ int QString::compare_helper(const QChar *data1, int length1, const char *data2,
}
/*!
- \fn int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
+ \fn int QString::compare(const QString &s1, QStringView s2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
+ \overload compare()
+*/
+
+/*!
+ \fn int QString::compare(QStringView s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive)
\overload compare()
*/
@@ -5946,8 +5865,8 @@ int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2,
*/
/*!
- \fn int QString::localeAwareCompare(const QStringRef &other) const
- \since 4.5
+ \fn int QString::localeAwareCompare(QStringView other) const
+ \since 6.0
\overload localeAwareCompare()
Compares this string with the \a other string and returns an
@@ -5962,8 +5881,8 @@ int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2,
*/
/*!
- \fn int QString::localeAwareCompare(const QString &s1, const QStringRef &s2)
- \since 4.5
+ \fn int QString::localeAwareCompare(QStringView s1, QStringView s2)
+ \since 6.0
\overload localeAwareCompare()
Compares \a s1 with \a s2 and returns an integer less than, equal
@@ -10659,24 +10578,6 @@ QStringRef QStringRef::appendTo(QString *string) const
*/
/*!
- \fn QString &QString::append(const QStringRef &reference)
- \since 4.4
-
- Appends the given string \a reference to this string and returns the result.
- */
-QString &QString::append(const QStringRef &str)
-{
- if (str.string() == this) {
- str.appendTo(this);
- } else if (!str.isNull()) {
- int oldSize = size();
- resize(oldSize + str.size());
- memcpy(data() + oldSize, str.unicode(), str.size() * sizeof(QChar));
- }
- return *this;
-}
-
-/*!
\fn QStringRef::left(int n) const
\since 5.2
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 00c61063da..c6ef27c481 100644
--- a/src/corelib/text/qstring.h
+++ b/src/corelib/text/qstring.h
@@ -399,7 +399,6 @@ public:
int indexOf(QLatin1String s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_STRINGVIEW_LEVEL < 2
int indexOf(const QString &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- int indexOf(const QStringRef &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
Q_REQUIRED_RESULT int indexOf(QStringView s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
{ return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsizetype
@@ -407,7 +406,6 @@ public:
int lastIndexOf(QLatin1String s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_STRINGVIEW_LEVEL < 2
int lastIndexOf(const QString &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- int lastIndexOf(const QStringRef &s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
Q_REQUIRED_RESULT int lastIndexOf(QStringView s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept
@@ -416,13 +414,12 @@ public:
inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_STRINGVIEW_LEVEL < 2
inline bool contains(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- inline bool contains(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#endif
inline bool contains(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
inline bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
int count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
int count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
- int count(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
+ int count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const;
#if QT_CONFIG(regularexpression)
int indexOf(const QRegularExpression &re, int from = 0,
@@ -469,7 +466,6 @@ public:
#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 noexcept
{ return QtPrivate::startsWith(*this, s, cs); }
@@ -478,7 +474,6 @@ public:
#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 noexcept
{ return QtPrivate::endsWith(*this, s, cs); }
@@ -535,7 +530,6 @@ public:
QString &insert(int i, const QChar *uc, int len);
#if QT_STRINGVIEW_LEVEL < 2
inline QString &insert(int i, const QString &s) { return insert(i, s.constData(), s.length()); }
- inline QString &insert(int i, const QStringRef &s);
#endif
inline QString &insert(int i, QStringView v) { return insert(i, v.data(), v.length()); }
QString &insert(int i, QLatin1String s);
@@ -544,7 +538,6 @@ public:
QString &append(const QChar *uc, int len);
#if QT_STRINGVIEW_LEVEL < 2
QString &append(const QString &s);
- QString &append(const QStringRef &s);
#endif
inline QString &append(QStringView v) { return append(v.data(), v.length()); }
QString &append(QLatin1String s);
@@ -553,7 +546,6 @@ public:
inline QString &prepend(const QChar *uc, int len) { return insert(0, uc, len); }
#if QT_STRINGVIEW_LEVEL < 2
inline QString &prepend(const QString &s) { return insert(0, s); }
- inline QString &prepend(const QStringRef &s) { return insert(0, s); }
#endif
inline QString &prepend(QStringView v) { return prepend(v.data(), v.length()); }
inline QString &prepend(QLatin1String s) { return insert(0, s); }
@@ -568,7 +560,6 @@ public:
#if QT_STRINGVIEW_LEVEL < 2
inline QString &operator+=(const QString &s) { return append(s); }
- inline QString &operator+=(const QStringRef &s) { return append(s); }
#endif
inline QString &operator+=(QStringView v) { return append(v); }
inline QString &operator+=(QLatin1String s) { return append(s); }
@@ -737,7 +728,6 @@ public:
#if QT_STRINGVIEW_LEVEL < 2
int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
- inline int compare(const QStringRef &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
#endif
int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
inline int compare(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
@@ -754,16 +744,17 @@ public:
static inline int compare(QLatin1String s1, const QString &s2,
Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
{ return -s2.compare(s1, cs); }
-
- static int compare(const QString &s1, const QStringRef &s2,
- Qt::CaseSensitivity = Qt::CaseSensitive) noexcept;
+ static int compare(const QString &s1, QStringView s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
+ { return s1.compare(s2, cs); }
+ static int compare(QStringView s1, const QString &s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept
+ { return -s2.compare(s1, cs); }
int localeAwareCompare(const QString& s) const;
+ int localeAwareCompare(QStringView s) const;
static int localeAwareCompare(const QString& s1, const QString& s2)
{ return s1.localeAwareCompare(s2); }
- int localeAwareCompare(const QStringRef &s) const;
- static int localeAwareCompare(const QString& s1, const QStringRef& s2);
+ static int localeAwareCompare(QStringView s1, QStringView s2);
// ### Qt6: make inline except for the long long versions
short toShort(bool *ok=nullptr, int base=10) const;
@@ -1206,8 +1197,6 @@ inline QString::const_iterator QString::constEnd() const
#if QT_STRINGVIEW_LEVEL < 2
inline bool QString::contains(const QString &s, Qt::CaseSensitivity cs) const
{ return indexOf(s, 0, cs) != -1; }
-inline bool QString::contains(const QStringRef &s, Qt::CaseSensitivity cs) const
-{ return indexOf(s, 0, cs) != -1; }
#endif
inline bool QString::contains(QLatin1String s, Qt::CaseSensitivity cs) const
{ return indexOf(s, 0, cs) != -1; }
@@ -1680,14 +1669,8 @@ inline bool operator> (const QStringRef &lhs, const QString &rhs) noexcept { ret
inline bool operator<=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs >= lhs; }
inline bool operator>=(const QStringRef &lhs, const QString &rhs) noexcept { return rhs <= lhs; }
-#if QT_STRINGVIEW_LEVEL < 2
-inline int QString::compare(const QStringRef &s, Qt::CaseSensitivity cs) const noexcept
-{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
-#endif
inline int QString::compare(QStringView s, Qt::CaseSensitivity cs) const noexcept
{ return -s.compare(*this, cs); }
-inline int QString::compare(const QString &s1, const QStringRef &s2, Qt::CaseSensitivity cs) noexcept
-{ return QString::compare_helper(s1.constData(), s1.length(), s2.constData(), s2.length(), cs); }
inline int QStringRef::compare(const QString &s, Qt::CaseSensitivity cs) const noexcept
{ return QString::compare_helper(constData(), length(), s.constData(), s.length(), cs); }
inline int QStringRef::compare(const QStringRef &s, Qt::CaseSensitivity cs) const noexcept
@@ -1855,9 +1838,9 @@ inline QT_ASCII_CAST_WARN bool operator>=(const char *s1, const QStringRef &s2)
{ return QString::compare_helper(s2.constData(), s2.size(), s1, -1) <= 0; }
#endif // !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII)
-inline int QString::localeAwareCompare(const QStringRef &s) const
+inline int QString::localeAwareCompare(QStringView s) const
{ return localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
-inline int QString::localeAwareCompare(const QString& s1, const QStringRef& s2)
+inline int QString::localeAwareCompare(QStringView s1, QStringView s2)
{ return localeAwareCompare_helper(s1.constData(), s1.length(), s2.constData(), s2.length()); }
inline int QStringRef::localeAwareCompare(const QString &s) const
{ return QString::localeAwareCompare_helper(constData(), length(), s.constData(), s.length()); }
@@ -1881,9 +1864,6 @@ inline bool QStringRef::contains(QChar c, Qt::CaseSensitivity cs) const
inline bool QStringRef::contains(QStringView s, Qt::CaseSensitivity cs) const noexcept
{ return indexOf(s, 0, cs) != -1; }
-inline QString &QString::insert(int i, const QStringRef &s)
-{ return insert(i, s.constData(), s.length()); }
-
#if !defined(QT_USE_FAST_OPERATOR_PLUS) && !defined(QT_USE_QSTRINGBUILDER)
inline QString operator+(const QString &s1, const QStringRef &s2)
{ QString t; t.reserve(s1.size() + s2.size()); t += s1; t += s2; return t; }