Rename new slice() method sliced()

The recently-added slice() method has the problem that it's a noun
as well as a verb in the imperative. Like std::vector::empty, which
is both an adjective and a verb in the imperative, this may cause
confusion as to what the function does. Using the passive voice form
of slice(), sliced(), removes the confusion. While it can be read as
an adjective, too, that doesn't change the meaning compared to the
verb form.

Change-Id: If0aa01acb6cf5dd5eafa8226e3ea7f7a0c9da4f1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Marc Mutz 2020-06-10 15:00:48 +02:00
parent 7b15417b53
commit 3f6142f5a1
7 changed files with 42 additions and 42 deletions

View File

@ -2949,7 +2949,7 @@ QByteArray QByteArray::left(int len) const
Example:
\snippet code/src_corelib_text_qbytearray.cpp 28
\sa endsWith(), last(), first(), slice(), chopped(), chop(), truncate()
\sa endsWith(), last(), first(), sliced(), chopped(), chop(), truncate()
*/
QByteArray QByteArray::right(int len) const
{
@ -2964,7 +2964,7 @@ QByteArray QByteArray::right(int len) const
Returns a byte array containing \a len bytes from this byte array,
starting at position \a pos.
\obsolete Use slice() instead in new code.
\obsolete Use sliced() instead in new code.
If \a len is -1 (the default), or \a pos + \a len >= size(),
returns a byte array containing all bytes starting at position \a
@ -2973,7 +2973,7 @@ QByteArray QByteArray::right(int len) const
Example:
\snippet code/src_corelib_text_qbytearray.cpp 29
\sa first(), last(), slice(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), chopped(), chop(), truncate()
*/
QByteArray QByteArray::mid(int pos, int len) const
@ -3007,7 +3007,7 @@ QByteArray QByteArray::mid(int pos, int len) const
\note The behavior is undefined when \a n < 0 or \a n > size().
\sa last(), slice(), from(), startsWith(), chopped(), chop(), truncate()
\sa last(), sliced(), from(), startsWith(), chopped(), chop(), truncate()
*/
/*!
@ -3018,11 +3018,11 @@ QByteArray QByteArray::mid(int pos, int len) const
\note The behavior is undefined when \a n < 0 or \a n > size().
\sa first(), slice(), from(), endsWith(), chopped(), chop(), truncate()
\sa first(), sliced(), from(), endsWith(), chopped(), chop(), truncate()
*/
/*!
\fn QByteArray QByteArray::slice(qsizetype pos, qsizetype n) const
\fn QByteArray QByteArray::sliced(qsizetype pos, qsizetype n) const
\since 6.0
Returns a byte array containing the \a n bytes of this object starting
@ -3043,7 +3043,7 @@ QByteArray QByteArray::mid(int pos, int len) const
\note The behavior is undefined when \a pos < 0 or \a pos > size().
\sa first(), last(), slice(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), chopped(), chop(), truncate()
*/
/*!

View File

@ -231,7 +231,7 @@ public:
{ Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QByteArray(data() + size() - n, int(n)); }
Q_REQUIRED_RESULT QByteArray from(qsizetype pos) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QByteArray(data() + pos, size() - int(pos)); }
Q_REQUIRED_RESULT QByteArray slice(qsizetype pos, qsizetype n) const
Q_REQUIRED_RESULT QByteArray sliced(qsizetype pos, qsizetype n) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QByteArray(data() + pos, int(n)); }
Q_REQUIRED_RESULT QByteArray chopped(int len) const
{ Q_ASSERT(len >= 0); Q_ASSERT(len <= size()); return first(size() - len); }

View File

@ -4516,7 +4516,7 @@ QString QString::left(int n) const
\snippet qstring/main.cpp 48
\sa endsWith(), last(), first(), slice(), chopped(), chop(), truncate()
\sa endsWith(), last(), first(), sliced(), chopped(), chop(), truncate()
*/
QString QString::right(int n) const
{
@ -4529,7 +4529,7 @@ QString QString::right(int n) const
Returns a string that contains \a n characters of this string,
starting at the specified \a position index.
\obsolete Use slice() instead in new code.
\obsolete Use sliced() instead in new code.
Returns a null string if the \a position index exceeds the
length of the string. If there are less than \a n characters
@ -4541,7 +4541,7 @@ QString QString::right(int n) const
\snippet qstring/main.cpp 34
\sa first(), last(), slice(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), chopped(), chop(), truncate()
*/
QString QString::mid(int position, int n) const
@ -4576,7 +4576,7 @@ QString QString::mid(int position, int n) const
\note The behavior is undefined when \a n < 0 or \a n > size().
\sa last(), slice(), from(), startsWith(), chopped(), chop(), truncate()
\sa last(), sliced(), from(), startsWith(), chopped(), chop(), truncate()
*/
/*!
@ -4587,11 +4587,11 @@ QString QString::mid(int position, int n) const
\note The behavior is undefined when \a n < 0 or \a n > size().
\sa first(), slice(), from(), endsWith(), chopped(), chop(), truncate()
\sa first(), sliced(), from(), endsWith(), chopped(), chop(), truncate()
*/
/*!
\fn QString QString::slice(qsizetype pos, qsizetype n) const
\fn QString QString::sliced(qsizetype pos, qsizetype n) const
\since 6.0
Returns a string that contains \a n characters of this string,
@ -4612,7 +4612,7 @@ QString QString::mid(int position, int n) const
\note The behavior is undefined when \a pos < 0 or \a pos > size().
\sa first(), last(), slice(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), chopped(), chop(), truncate()
*/
/*!

View File

@ -454,7 +454,7 @@ public:
{ Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data() + size() - n, int(n)); }
Q_REQUIRED_RESULT QString from(qsizetype pos) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QString(data() + pos, size() - int(pos)); }
Q_REQUIRED_RESULT QString slice(qsizetype pos, qsizetype n) const
Q_REQUIRED_RESULT QString sliced(qsizetype pos, qsizetype n) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QString(data() + pos, int(n)); }
Q_REQUIRED_RESULT QString chopped(int n) const
{ Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return first(size() - n); }

View File

@ -616,7 +616,7 @@ QT_BEGIN_NAMESPACE
Returns the substring of length \a length starting at position
\a start in this object.
\obsolete Use slice() instead in new code.
\obsolete Use sliced() instead in new code.
Returns an empty string view if \a start exceeds the
length of the string. If there are less than \a length characters
@ -624,7 +624,7 @@ QT_BEGIN_NAMESPACE
\a length is negative (default), the function returns all characters that
are available from \a start.
\sa first(), last(), slice(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), chopped(), chop(), truncate()
*/
/*!
@ -638,7 +638,7 @@ QT_BEGIN_NAMESPACE
The entire string is returned if \a length is greater than or equal
to size(), or less than zero.
\sa first(), last(), slice(), startsWith(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), startsWith(), chopped(), chop(), truncate()
*/
/*!
@ -652,7 +652,7 @@ QT_BEGIN_NAMESPACE
The entire string is returned if \a length is greater than or equal
to size(), or less than zero.
\sa first(), last(), slice(), endsWith(), chopped(), chop(), truncate()
\sa first(), last(), sliced(), endsWith(), chopped(), chop(), truncate()
*/
/*!
@ -679,7 +679,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
\fn QStringView QStringView::slice(qsizetype pos, qsizetype n) const
\fn QStringView QStringView::sliced(qsizetype pos, qsizetype n) const
\since 6.0
Returns a string view that points to \a n characters of this string,

View File

@ -282,7 +282,7 @@ public:
{ Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data + size() - n, int(n)); }
Q_REQUIRED_RESULT constexpr QStringView from(qsizetype pos) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QStringView(m_data + pos, size() - int(pos)); }
Q_REQUIRED_RESULT constexpr QStringView slice(qsizetype pos, qsizetype n) const
Q_REQUIRED_RESULT constexpr QStringView sliced(qsizetype pos, qsizetype n) const
{ Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QStringView(m_data + pos, int(n)); }
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QStringView chopped(qsizetype n) const
{ return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, m_size - n); }

View File

@ -632,8 +632,8 @@ private:
void right_data();
template <typename String> void right_impl();
void slice_data();
template <typename String> void slice_impl();
void sliced_data();
template <typename String> void sliced_impl();
void first_data();
template <typename String> void first_impl();
@ -679,12 +679,12 @@ private Q_SLOTS:
void right_QByteArray_data();
void right_QByteArray() { right_impl<QByteArray>(); }
void slice_QString_data() { slice_data(); }
void slice_QString() { slice_impl<QString>(); }
void slice_QStringView_data() { slice_data(); }
void slice_QStringView() { slice_impl<QStringView>(); }
void slice_QByteArray_data() { slice_data(); }
void slice_QByteArray() { slice_impl<QByteArray>(); }
void sliced_QString_data() { sliced_data(); }
void sliced_QString() { sliced_impl<QString>(); }
void sliced_QStringView_data() { sliced_data(); }
void sliced_QStringView() { sliced_impl<QStringView>(); }
void sliced_QByteArray_data() { sliced_data(); }
void sliced_QByteArray() { sliced_impl<QByteArray>(); }
void first_truncate_QString_data() { first_data(); }
void first_truncate_QString() { first_impl<QString>(); }
@ -1529,9 +1529,9 @@ void tst_QStringApiSymmetry::tok_impl() const
void tst_QStringApiSymmetry::mid_data()
{
slice_data();
sliced_data();
// mid() has a wider contract compared to slize(), so test those cases here:
// mid() has a wider contract compared to sliced(), so test those cases here:
#define ROW(base, p, n, r1, r2) \
QTest::addRow("%s %d %d", #base, p, n) << QStringRef(&base) << QLatin1String(#base) << p << n << QStringRef(&r1) << QStringRef(&r2)
@ -1727,7 +1727,7 @@ void tst_QStringApiSymmetry::right_impl()
}
}
void tst_QStringApiSymmetry::slice_data()
void tst_QStringApiSymmetry::sliced_data()
{
QTest::addColumn<QStringRef>("unicode");
QTest::addColumn<QLatin1String>("latin1");
@ -1767,7 +1767,7 @@ void tst_QStringApiSymmetry::slice_data()
}
template <typename String>
void tst_QStringApiSymmetry::slice_impl()
void tst_QStringApiSymmetry::sliced_impl()
{
QFETCH(const QStringRef, unicode);
QFETCH(const QLatin1String, latin1);
@ -1782,27 +1782,27 @@ void tst_QStringApiSymmetry::slice_impl()
{
const auto from = s.from(pos);
const auto slice = s.slice(pos, n);
const auto sliced = s.sliced(pos, n);
QCOMPARE(from, result);
QCOMPARE(from.isNull(), result.isNull());
QCOMPARE(from.isEmpty(), result.isEmpty());
QCOMPARE(slice, result2);
QCOMPARE(slice.isNull(), result2.isNull());
QCOMPARE(slice.isEmpty(), result2.isEmpty());
QCOMPARE(sliced, result2);
QCOMPARE(sliced.isNull(), result2.isNull());
QCOMPARE(sliced.isEmpty(), result2.isEmpty());
}
{
const auto from = detached(s).from(pos);
const auto slice = detached(s).slice(pos, n);
const auto sliced = detached(s).sliced(pos, n);
QCOMPARE(from, result);
QCOMPARE(from.isNull(), result.isNull());
QCOMPARE(from.isEmpty(), result.isEmpty());
QCOMPARE(slice, result2);
QCOMPARE(slice.isNull(), result2.isNull());
QCOMPARE(slice.isEmpty(), result2.isEmpty());
QCOMPARE(sliced, result2);
QCOMPARE(sliced.isNull(), result2.isNull());
QCOMPARE(sliced.isEmpty(), result2.isEmpty());
}
}