From 9117e3850b9d395a9741fa4b63c5b59ea7767390 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sat, 27 Jun 2020 11:26:42 +0200 Subject: [PATCH] Rename from() to sliced() After API discussions, agreement was that from(n) is a bad name for the method. Let's go with sliced(n) instead. Change-Id: I0338cc150148a5008c3ee72bd8fda96fb93e9c35 Reviewed-by: Thiago Macieira --- src/corelib/text/qbytearray.cpp | 9 +++++---- src/corelib/text/qbytearray.h | 2 +- src/corelib/text/qstring.cpp | 7 ++++--- src/corelib/text/qstring.h | 2 +- src/corelib/text/qstringview.cpp | 3 ++- src/corelib/text/qstringview.h | 2 +- .../text/qstringapisymmetry/tst_qstringapisymmetry.cpp | 4 ++-- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index c138765e15..299c723a55 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -2902,7 +2902,7 @@ QByteArray QByteArray::mid(int pos, int len) const \note The behavior is undefined when \a n < 0 or \a n > size(). - \sa last(), sliced(), from(), startsWith(), chopped(), chop(), truncate() + \sa last(), sliced(), startsWith(), chopped(), chop(), truncate() */ /*! @@ -2913,7 +2913,7 @@ QByteArray QByteArray::mid(int pos, int len) const \note The behavior is undefined when \a n < 0 or \a n > size(). - \sa first(), sliced(), from(), endsWith(), chopped(), chop(), truncate() + \sa first(), sliced(), endsWith(), chopped(), chop(), truncate() */ /*! @@ -2926,12 +2926,13 @@ QByteArray QByteArray::mid(int pos, int len) const \note The behavior is undefined when \a pos < 0, \a n < 0, or \a pos + \a n > size(). - \sa first(), last(), from(), chopped(), chop(), truncate() + \sa first(), last(), chopped(), chop(), truncate() */ /*! - \fn QByteArray QByteArray::from(qsizetype pos) const + \fn QByteArray QByteArray::sliced(qsizetype pos) const \since 6.0 + \overload Returns a byte array containing the bytes starting at position \a pos in this object, and extending to the end of this object. diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h index f4d4bf0745..045a05c54a 100644 --- a/src/corelib/text/qbytearray.h +++ b/src/corelib/text/qbytearray.h @@ -226,7 +226,7 @@ public: { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QByteArray(data(), int(n)); } Q_REQUIRED_RESULT QByteArray last(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QByteArray(data() + size() - n, int(n)); } - Q_REQUIRED_RESULT QByteArray from(qsizetype pos) const + Q_REQUIRED_RESULT QByteArray sliced(qsizetype pos) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QByteArray(data() + pos, size() - int(pos)); } 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)); } diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 36f61aed7d..ae39823df2 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -4554,7 +4554,7 @@ QString QString::mid(qsizetype position, qsizetype n) const \note The behavior is undefined when \a n < 0 or \a n > size(). - \sa last(), sliced(), from(), startsWith(), chopped(), chop(), truncate() + \sa last(), sliced(), startsWith(), chopped(), chop(), truncate() */ /*! @@ -4565,7 +4565,7 @@ QString QString::mid(qsizetype position, qsizetype n) const \note The behavior is undefined when \a n < 0 or \a n > size(). - \sa first(), sliced(), from(), endsWith(), chopped(), chop(), truncate() + \sa first(), sliced(), endsWith(), chopped(), chop(), truncate() */ /*! @@ -4582,8 +4582,9 @@ QString QString::mid(qsizetype position, qsizetype n) const */ /*! - \fn QString QString::from(qsizetype pos) const + \fn QString QString::sliced(qsizetype pos) const \since 6.0 + \overload Returns a string that contains the portion of this string starting at position \a pos and extending to its end. diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index f3222155b8..45578debd6 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -441,7 +441,7 @@ public: { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data(), n); } Q_REQUIRED_RESULT QString last(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data() + size() - n, n); } - Q_REQUIRED_RESULT QString from(qsizetype pos) const + Q_REQUIRED_RESULT QString sliced(qsizetype pos) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QString(data() + pos, size() - pos); } 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, n); } diff --git a/src/corelib/text/qstringview.cpp b/src/corelib/text/qstringview.cpp index 985d87ac51..4ad8a8f38f 100644 --- a/src/corelib/text/qstringview.cpp +++ b/src/corelib/text/qstringview.cpp @@ -692,8 +692,9 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QStringView QStringView::from(qsizetype pos) const + \fn QStringView QStringView::sliced(qsizetype pos) const \since 6.0 + \overload Returns a string view starting at position \a pos in this object, and extending to its end. diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 17b60fdc42..58412974bc 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -280,7 +280,7 @@ public: { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data, n); } Q_REQUIRED_RESULT constexpr QStringView last(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QStringView(m_data + size() - n, n); } - Q_REQUIRED_RESULT constexpr QStringView from(qsizetype pos) const + Q_REQUIRED_RESULT constexpr QStringView sliced(qsizetype pos) const { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QStringView(m_data + pos, size() - pos); } 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, n); } diff --git a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp index d363c01f68..69ad52c08b 100644 --- a/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp +++ b/tests/auto/corelib/text/qstringapisymmetry/tst_qstringapisymmetry.cpp @@ -1780,7 +1780,7 @@ void tst_QStringApiSymmetry::sliced_impl() const auto s = make(unicode, latin1, utf8); { - const auto from = s.from(pos); + const auto from = s.sliced(pos); const auto sliced = s.sliced(pos, n); QCOMPARE(from, result); @@ -1792,7 +1792,7 @@ void tst_QStringApiSymmetry::sliced_impl() QCOMPARE(sliced.isEmpty(), result2.isEmpty()); } { - const auto from = detached(s).from(pos); + const auto from = detached(s).sliced(pos); const auto sliced = detached(s).sliced(pos, n); QCOMPARE(from, result);