diff options
-rw-r--r-- | src/corelib/io/qurlidna.cpp | 2 | ||||
-rw-r--r-- | src/corelib/text/qchar.cpp | 40 | ||||
-rw-r--r-- | src/corelib/text/qstring.cpp | 381 | ||||
-rw-r--r-- | src/corelib/text/qstring.h | 216 | ||||
-rw-r--r-- | src/corelib/text/qstringmatcher.cpp | 4 | ||||
-rw-r--r-- | src/corelib/text/qstringmatcher.h | 4 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstring/tst_qstring.cpp | 42 | ||||
-rw-r--r-- | tests/auto/corelib/text/qstringref/tst_qstringref.cpp | 22 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp | 24 |
9 files changed, 360 insertions, 375 deletions
diff --git a/src/corelib/io/qurlidna.cpp b/src/corelib/io/qurlidna.cpp index b5774a0dc8..f034509bcc 100644 --- a/src/corelib/io/qurlidna.cpp +++ b/src/corelib/io/qurlidna.cpp @@ -2087,7 +2087,7 @@ Q_AUTOTEST_EXPORT bool qt_nameprep(QString *source, int from) // Normalize to Unicode 3.2 form KC extern void qt_string_normalize(QString *data, QString::NormalizationForm mode, - QChar::UnicodeVersion version, int from); + QChar::UnicodeVersion version, qsizetype from); qt_string_normalize(source, QString::NormalizationForm_KC, QChar::Unicode_3_2, firstNonAscii > from ? firstNonAscii - 1 : from); diff --git a/src/corelib/text/qchar.cpp b/src/corelib/text/qchar.cpp index 628d4ab370..a816e01b68 100644 --- a/src/corelib/text/qchar.cpp +++ b/src/corelib/text/qchar.cpp @@ -1439,7 +1439,7 @@ enum { // buffer has to have a length of 3. It's needed for Hangul decomposition static const unsigned short * QT_FASTCALL decompositionHelper - (uint ucs4, int *length, int *tag, unsigned short *buffer) + (uint ucs4, qsizetype *length, int *tag, unsigned short *buffer) { if (ucs4 >= Hangul_SBase && ucs4 < Hangul_SBase + Hangul_SCount) { // compute Hangul syllable decomposition as per UAX #15 @@ -1484,7 +1484,7 @@ QString QChar::decomposition() const QString QChar::decomposition(char32_t ucs4) { unsigned short buffer[3]; - int length; + qsizetype length; int tag; const unsigned short *d = decompositionHelper(ucs4, &length, &tag, buffer); return QString(reinterpret_cast<const QChar *>(d), length); @@ -1910,9 +1910,9 @@ QDataStream &operator>>(QDataStream &in, QChar &chr) // --------------------------------------------------------------------------- -static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion version, int from) +static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion version, qsizetype from) { - int length; + qsizetype length; int tag; unsigned short buffer[3]; @@ -1937,7 +1937,7 @@ static void decomposeHelper(QString *str, bool canonical, QChar::UnicodeVersion if (!d || (canonical && tag != QChar::Canonical)) continue; - int pos = uc - utf16; + qsizetype pos = uc - utf16; s.replace(pos, QChar::requiresSurrogates(ucs4) ? 2 : 1, reinterpret_cast<const QChar *>(d), length); // since the replace invalidates the pointers and we do decomposition recursive utf16 = reinterpret_cast<unsigned short *>(s.data()); @@ -2010,7 +2010,7 @@ static uint inline ligatureHelper(uint u1, uint u2) return 0; } -static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) +static void composeHelper(QString *str, QChar::UnicodeVersion version, qsizetype from) { QString &s = *str; @@ -2018,13 +2018,13 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) return; uint stcode = 0; // starter code point - int starter = -1; // starter position - int next = -1; // to prevent i == next + qsizetype starter = -1; // starter position + qsizetype next = -1; // to prevent i == next int lastCombining = 255; // to prevent combining > lastCombining - int pos = from; + qsizetype pos = from; while (pos < s.length()) { - int i = pos; + qsizetype i = pos; char32_t uc = s.at(pos).unicode(); if (QChar(uc).isHighSurrogate() && pos < s.length()-1) { ushort low = s.at(pos+1).unicode(); @@ -2051,7 +2051,7 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) stcode = ligature; QChar *d = s.data(); // ligatureHelper() never changes planes - int j = 0; + qsizetype j = 0; for (QChar ch : QChar::fromUcs4(ligature)) d[starter + j++] = ch; s.remove(i, j); @@ -2070,17 +2070,17 @@ static void composeHelper(QString *str, QChar::UnicodeVersion version, int from) } -static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, int from) +static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, qsizetype from) { QString &s = *str; - const int l = s.length()-1; + const qsizetype l = s.length()-1; char32_t u1, u2; char16_t c1, c2; - int pos = from; + qsizetype pos = from; while (pos < l) { - int p2 = pos+1; + qsizetype p2 = pos+1; u1 = s.at(pos).unicode(); if (QChar::isHighSurrogate(u1)) { const char16_t low = s.at(p2).unicode(); @@ -2122,7 +2122,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in if (c1 > c2) { QChar *uc = s.data(); - int p = pos; + qsizetype p = pos; // exchange characters for (QChar ch : QChar::fromUcs4(u2)) uc[p++] = ch; @@ -2152,7 +2152,7 @@ static void canonicalOrderHelper(QString *str, QChar::UnicodeVersion version, in // returns true if the text is in a desired Normalization Form already; false otherwise. // sets lastStable to the position of the last stable code point -static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationForm mode, int from, int *lastStable) +static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationForm mode, qsizetype from, qsizetype *lastStable) { static_assert(QString::NormalizationForm_D == 0); static_assert(QString::NormalizationForm_C == 1); @@ -2162,15 +2162,15 @@ static bool normalizationQuickCheckHelper(QString *str, QString::NormalizationFo enum { NFQC_YES = 0, NFQC_NO = 1, NFQC_MAYBE = 3 }; const ushort *string = reinterpret_cast<const ushort *>(str->constData()); - int length = str->length(); + qsizetype length = str->length(); // this avoids one out of bounds check in the loop while (length > from && QChar::isHighSurrogate(string[length - 1])) --length; uchar lastCombining = 0; - for (int i = from; i < length; ++i) { - int pos = i; + for (qsizetype i = from; i < length; ++i) { + qsizetype pos = i; char32_t uc = string[i]; if (uc < 0x80) { // ASCII characters are stable code points diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index c98b1f82b6..36f61aed7d 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -1194,7 +1194,7 @@ static int ucstrcmp(const QChar *a, size_t alen, const char *b, size_t blen) return cmp ? cmp : lencmp(alen, blen); } -static int latin1nicmp(const char *lhsChar, int lSize, const char *rhsChar, int rSize) +static int latin1nicmp(const char *lhsChar, qsizetype lSize, const char *rhsChar, qsizetype rSize) { constexpr uchar latin1Lower[256] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, @@ -1221,12 +1221,12 @@ static int latin1nicmp(const char *lhsChar, int lSize, const char *rhsChar, int return rSize ? -1 : 0; if (!rSize) return 1; - const int size = std::min(lSize, rSize); + const qsizetype size = std::min(lSize, rSize); const uchar *lhs = reinterpret_cast<const uchar *>(lhsChar); const uchar *rhs = reinterpret_cast<const uchar *>(rhsChar); Q_ASSERT(lhs && rhs); // since both lSize and rSize are positive - for (int i = 0; i < size; i++) { + for (qsizetype i = 0; i < size; i++) { Q_ASSERT(lhs[i] && rhs[i]); if (int res = latin1Lower[lhs[i]] - latin1Lower[rhs[i]]) return res; @@ -1778,13 +1778,6 @@ inline char qToLower(char ch) \section1 Maximum size and out-of-memory conditions - The current version of QString is limited to just under 2 GB (2^31 bytes) - in size. The exact value is architecture-dependent, since it depends on the - overhead required for managing the data block, but is no more than 32 - bytes. Raw data blocks are also limited by the use of \c int type in the - current version to 2 GB minus 1 byte. Since QString uses two bytes per - character, that translates to just under 2^30 characters in one QString. - In case memory allocation fails, QString will throw a \c std::bad_alloc exception. Out of memory conditions in the Qt containers are the only case where Qt will throw exceptions. @@ -2037,7 +2030,7 @@ inline char qToLower(char ch) \sa fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), fromStdU16String(), fromStdU32String() */ -/*! \fn QString QString::fromWCharArray(const wchar_t *string, int size) +/*! \fn QString QString::fromWCharArray(const wchar_t *string, qsizetype size) \since 4.2 Returns a copy of the \a string, where the encoding of \a string depends on @@ -2062,9 +2055,9 @@ inline char qToLower(char ch) \sa utf16(), toLatin1(), toUtf8(), toLocal8Bit(), toStdU16String(), toStdU32String() */ -int QString::toUcs4_helper(const ushort *uc, int length, uint *out) +qsizetype QString::toUcs4_helper(const ushort *uc, qsizetype length, uint *out) { - int count = 0; + qsizetype count = 0; QStringIterator i(QStringView(uc, length)); while (i.hasNext()) @@ -2073,7 +2066,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out) return count; } -/*! \fn int QString::toWCharArray(wchar_t *array) const +/*! \fn QString::toWCharArray(wchar_t *array) const \since 4.2 Fills the \a array with the data contained in this QString object. @@ -2119,7 +2112,7 @@ int QString::toUcs4_helper(const ushort *uc, int length, uint *out) \sa fromRawData() */ -QString::QString(const QChar *unicode, int size) +QString::QString(const QChar *unicode, qsizetype size) { if (!unicode) { d.clear(); @@ -2145,7 +2138,7 @@ QString::QString(const QChar *unicode, int size) \sa fill() */ -QString::QString(int size, QChar ch) +QString::QString(qsizetype size, QChar ch) { if (size <= 0) { d = DataPointer::fromRawData(&_empty, 0); @@ -2160,13 +2153,13 @@ QString::QString(int size, QChar ch) } } -/*! \fn QString::QString(int size, Qt::Initialization) +/*! \fn QString::QString(qsizetype size, Qt::Initialization) \internal Constructs a string of the given \a size without initializing the characters. This is only used in \c QStringBuilder::toString(). */ -QString::QString(int size, Qt::Initialization) +QString::QString(qsizetype size, Qt::Initialization) { d = DataPointer(Data::allocate(size + 1), size); d.data()[size] = '\0'; @@ -2273,7 +2266,7 @@ QString::QString(QChar ch) \sa truncate(), reserve() */ -void QString::resize(int size) +void QString::resize(qsizetype size) { if (size < 0) size = 0; @@ -2295,16 +2288,16 @@ void QString::resize(int size) \snippet qstring/main.cpp 46 */ -void QString::resize(int size, QChar fillChar) +void QString::resize(qsizetype size, QChar fillChar) { - const int oldSize = length(); + const qsizetype oldSize = length(); resize(size); - const int difference = length() - oldSize; + const qsizetype difference = length() - oldSize; if (difference > 0) std::fill_n(d.data() + oldSize, difference, fillChar.unicode()); } -/*! \fn int QString::capacity() const +/*! \fn qsizetype QString::capacity() const Returns the maximum number of characters that can be stored in the string without forcing a reallocation. @@ -2321,7 +2314,7 @@ void QString::resize(int size, QChar fillChar) */ /*! - \fn void QString::reserve(int size) + \fn void QString::reserve(qsizetype size) Attempts to allocate memory for at least \a size characters. If you know in advance how large the string will be, you can call @@ -2357,7 +2350,7 @@ void QString::resize(int size, QChar fillChar) \sa reserve(), capacity() */ -void QString::reallocData(uint alloc, bool grow) +void QString::reallocData(size_t alloc, bool grow) { auto allocOptions = d->detachFlags(); if (grow) @@ -2373,13 +2366,6 @@ void QString::reallocData(uint alloc, bool grow) } } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -void QString::expand(int i) -{ - resize(qMax(i + 1, size()), QLatin1Char(' ')); -} -#endif - /*! \fn void QString::clear() Clears the contents of the string and makes it null. @@ -2475,7 +2461,7 @@ QString &QString::operator=(QChar ch) } /*! - \fn QString& QString::insert(int position, const QString &str) + \fn QString& QString::insert(qsizetype position, const QString &str) Inserts the string \a str at the given index \a position and returns a reference to this string. @@ -2492,7 +2478,7 @@ QString &QString::operator=(QChar ch) /*! - \fn QString& QString::insert(int position, const QStringRef &str) + \fn QString& QString::insert(qsizetype position, const QStringRef &str) \since 5.5 \overload insert() @@ -2505,7 +2491,7 @@ QString &QString::operator=(QChar ch) /*! - \fn QString& QString::insert(int position, QStringView str) + \fn QString& QString::insert(qsizetype position, QStringView str) \since 6.0 \overload insert() @@ -2518,7 +2504,7 @@ QString &QString::operator=(QChar ch) /*! - \fn QString& QString::insert(int position, const char *str) + \fn QString& QString::insert(qsizetype position, const char *str) \since 5.5 \overload insert() @@ -2536,7 +2522,7 @@ QString &QString::operator=(QChar ch) /*! - \fn QString& QString::insert(int position, const QByteArray &str) + \fn QString& QString::insert(qsizetype position, const QByteArray &str) \since 5.5 \overload insert() @@ -2554,18 +2540,18 @@ QString &QString::operator=(QChar ch) /*! - \fn QString &QString::insert(int position, QLatin1String str) + \fn QString &QString::insert(qsizetype position, QLatin1String str) \overload insert() Inserts the Latin-1 string \a str at the given index \a position. */ -QString &QString::insert(int i, QLatin1String str) +QString &QString::insert(qsizetype i, QLatin1String str) { const char *s = str.latin1(); if (i < 0 || !s || !(*s)) return *this; - int len = str.size(); + qsizetype len = str.size(); if (Q_UNLIKELY(i > size())) resize(i + len, QLatin1Char(' ')); else @@ -2577,13 +2563,13 @@ QString &QString::insert(int i, QLatin1String str) } /*! - \fn QString& QString::insert(int position, const QChar *unicode, int size) + \fn QString& QString::insert(qsizetype position, const QChar *unicode, qsizetype size) \overload insert() Inserts the first \a size characters of the QChar array \a unicode at the given index \a position in the string. */ -QString& QString::insert(int i, const QChar *unicode, int size) +QString& QString::insert(qsizetype i, const QChar *unicode, qsizetype size) { if (i < 0 || size <= 0) return *this; @@ -2603,13 +2589,13 @@ QString& QString::insert(int i, const QChar *unicode, int size) } /*! - \fn QString& QString::insert(int position, QChar ch) + \fn QString& QString::insert(qsizetype position, QChar ch) \overload insert() Inserts \a ch at the given index \a position in the string. */ -QString& QString::insert(int i, QChar ch) +QString& QString::insert(qsizetype i, QChar ch) { if (i < 0) i += d.size; @@ -2664,7 +2650,7 @@ QString &QString::append(const QString &str) Appends \a len characters from the QChar array \a str to this string. */ -QString &QString::append(const QChar *str, int len) +QString &QString::append(const QChar *str, qsizetype len) { if (str && len > 0) { if (d->needsDetach() || size() + len > capacity()) @@ -2685,7 +2671,7 @@ QString &QString::append(QLatin1String str) { const char *s = str.latin1(); if (s) { - int len = str.size(); + qsizetype len = str.size(); if (d->needsDetach() || size() + len > capacity()) reallocData(uint(size() + len) + 1u, true); char16_t *i = d.data() + d.size; @@ -2734,7 +2720,7 @@ QString &QString::append(QLatin1String str) QString &QString::append(QChar ch) { if (d->needsDetach() || size() + 1 > capacity()) - reallocData(uint(d.size) + 2u, true); + reallocData(d.size + 2u, true); d.data()[d.size++] = ch.unicode(); d.data()[d.size] = '\0'; return *this; @@ -2759,7 +2745,7 @@ QString &QString::append(QChar ch) Prepends the Latin-1 string \a str to this string. */ -/*! \fn QString &QString::prepend(const QChar *str, int len) +/*! \fn QString &QString::prepend(const QChar *str, qsizetype len) \since 5.5 \overload prepend() @@ -2821,7 +2807,7 @@ QString &QString::append(QChar ch) */ /*! - \fn QString &QString::remove(int position, int n) + \fn QString &QString::remove(qsizetype position, qsizetype n) Removes \a n characters from the string, starting at the given \a position index, and returns a reference to the string. @@ -2834,11 +2820,11 @@ QString &QString::append(QChar ch) \sa insert(), replace() */ -QString &QString::remove(int pos, int len) +QString &QString::remove(qsizetype pos, qsizetype len) { if (pos < 0) // count from end of string pos += size(); - if (uint(pos) >= uint(size())) { + if (size_t(pos) >= size_t(size())) { // range problems } else if (len >= size() - pos) { resize(pos); // truncate @@ -2859,7 +2845,7 @@ static void removeStringImpl(QString &s, const T &needle, Qt::CaseSensitivity cs return; // avoid detach if nothing to do: - int i = s.indexOf(needle, 0, cs); + qsizetype i = s.indexOf(needle, 0, cs); if (i < 0) return; @@ -2938,7 +2924,7 @@ QString &QString::remove(QLatin1String str, Qt::CaseSensitivity cs) */ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) { - const int idx = indexOf(ch, 0, cs); + const qsizetype idx = indexOf(ch, 0, cs); if (idx != -1) { const auto first = begin(); // implicit detach() auto last = end(); @@ -2969,7 +2955,7 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) */ /*! - \fn QString &QString::replace(int position, int n, const QString &after) + \fn QString &QString::replace(qsizetype position, qsizetype n, const QString &after) Replaces \a n characters beginning at index \a position with the string \a after and returns a reference to this string. @@ -2984,38 +2970,38 @@ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) \sa insert(), remove() */ -QString &QString::replace(int pos, int len, const QString &after) +QString &QString::replace(qsizetype pos, qsizetype len, const QString &after) { return replace(pos, len, after.constData(), after.length()); } /*! - \fn QString &QString::replace(int position, int n, const QChar *unicode, int size) + \fn QString &QString::replace(qsizetype position, qsizetype n, const QChar *unicode, qsizetype size) \overload replace() Replaces \a n characters beginning at index \a position with the first \a size characters of the QChar array \a unicode and returns a reference to this string. */ -QString &QString::replace(int pos, int len, const QChar *unicode, int size) +QString &QString::replace(qsizetype pos, qsizetype len, const QChar *unicode, qsizetype size) { - if (uint(pos) > uint(this->size())) + if (size_t(pos) > size_t(this->size())) return *this; if (len > this->size() - pos) len = this->size() - pos; - uint index = pos; + size_t index = pos; replace_helper(&index, 1, len, unicode, size); return *this; } /*! - \fn QString &QString::replace(int position, int n, QChar after) + \fn QString &QString::replace(qsizetype position, qsizetype n, QChar after) \overload replace() Replaces \a n characters beginning at index \a position with the character \a after and returns a reference to this string. */ -QString &QString::replace(int pos, int len, QChar after) +QString &QString::replace(qsizetype pos, qsizetype len, QChar after) { return replace(pos, len, &after, 1); } @@ -3044,7 +3030,7 @@ QString &QString::replace(const QString &before, const QString &after, Qt::CaseS } namespace { // helpers for replace and its helper: -QChar *textCopy(const QChar *start, int len) +QChar *textCopy(const QChar *start, qsizetype len) { const size_t size = len * sizeof(QChar); QChar *const copy = static_cast<QChar *>(::malloc(size)); @@ -3064,7 +3050,7 @@ static bool pointsIntoRange(const QChar *ptr, const char16_t *base, qsizetype le /*! \internal */ -void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen) +void QString::replace_helper(size_t *indices, qsizetype nIndices, qsizetype blen, const QChar *after, qsizetype alen) { // Copy after if it lies inside our own d.b area (which we could // possibly invalidate via a realloc or modify by replacement). @@ -3076,18 +3062,18 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar if (blen == alen) { // replace in place detach(); - for (int i = 0; i < nIndices; ++i) + for (qsizetype i = 0; i < nIndices; ++i) memcpy(d.data() + indices[i], after, alen * sizeof(QChar)); } else if (alen < blen) { // replace from front detach(); - uint to = indices[0]; + size_t to = indices[0]; if (alen) memcpy(d.data()+to, after, alen*sizeof(QChar)); to += alen; - uint movestart = indices[0] + blen; - for (int i = 1; i < nIndices; ++i) { - int msize = indices[i] - movestart; + size_t movestart = indices[0] + blen; + for (qsizetype i = 1; i < nIndices; ++i) { + qsizetype msize = indices[i] - movestart; if (msize > 0) { memmove(d.data() + to, d.data() + movestart, msize * sizeof(QChar)); to += msize; @@ -3098,22 +3084,22 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar } movestart = indices[i] + blen; } - int msize = d.size - movestart; + qsizetype msize = d.size - movestart; if (msize > 0) memmove(d.data() + to, d.data() + movestart, msize * sizeof(QChar)); resize(d.size - nIndices*(blen-alen)); } else { // replace from back - int adjust = nIndices*(alen-blen); - int newLen = d.size + adjust; - int moveend = d.size; + qsizetype adjust = nIndices*(alen-blen); + qsizetype newLen = d.size + adjust; + qsizetype moveend = d.size; resize(newLen); while (nIndices) { --nIndices; - int movestart = indices[nIndices] + blen; - int insertstart = indices[nIndices] + nIndices*(alen-blen); - int moveto = insertstart + alen; + qsizetype movestart = indices[nIndices] + blen; + qsizetype insertstart = indices[nIndices] + nIndices*(alen-blen); + qsizetype moveto = insertstart + alen; memmove(d.data() + moveto, d.data() + movestart, (moveend - movestart)*sizeof(QChar)); memcpy(d.data() + insertstart, after, alen * sizeof(QChar)); @@ -3138,8 +3124,8 @@ void QString::replace_helper(uint *indices, int nIndices, int blen, const QChar If \a cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive. */ -QString &QString::replace(const QChar *before, int blen, - const QChar *after, int alen, +QString &QString::replace(const QChar *before, qsizetype blen, + const QChar *after, qsizetype alen, Qt::CaseSensitivity cs) { if (d.size == 0) { @@ -3155,10 +3141,10 @@ QString &QString::replace(const QChar *before, int blen, QStringMatcher matcher(before, blen, cs); QChar *beforeBuffer = nullptr, *afterBuffer = nullptr; - int index = 0; + qsizetype index = 0; while (1) { - uint indices[1024]; - uint pos = 0; + size_t indices[1024]; + size_t pos = 0; while (pos < 1024) { index = matcher.indexIn(*this, index); if (index == -1) @@ -3220,10 +3206,10 @@ QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs char16_t cc = (cs == Qt::CaseSensitive ? ch.unicode() : ch.toCaseFolded().unicode()); - int index = 0; + qsizetype index = 0; while (1) { - uint indices[1024]; - uint pos = 0; + size_t indices[1024]; + size_t pos = 0; if (cs == Qt::CaseSensitive) { while (pos < 1024 && index < size()) { if (d.data()[index] == cc) @@ -3261,7 +3247,7 @@ QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs) { if (d.size) { - const int idx = indexOf(before, 0, cs); + const qsizetype idx = indexOf(before, 0, cs); if (idx != -1) { detach(); const char16_t a = after.unicode(); @@ -3301,8 +3287,8 @@ QString& QString::replace(QChar before, QChar after, Qt::CaseSensitivity cs) */ QString &QString::replace(QLatin1String before, QLatin1String after, Qt::CaseSensitivity cs) { - int alen = after.size(); - int blen = before.size(); + qsizetype alen = after.size(); + qsizetype blen = before.size(); QVarLengthArray<char16_t> a(alen); QVarLengthArray<char16_t> b(blen); qt_from_latin1(a.data(), after.latin1(), alen); @@ -3324,7 +3310,7 @@ QString &QString::replace(QLatin1String before, QLatin1String after, Qt::CaseSen */ QString &QString::replace(QLatin1String before, const QString &after, Qt::CaseSensitivity cs) { - int blen = before.size(); + qsizetype blen = before.size(); QVarLengthArray<char16_t> b(blen); qt_from_latin1(b.data(), before.latin1(), blen); return replace((const QChar *)b.data(), blen, after.constData(), after.d.size, cs); @@ -3344,7 +3330,7 @@ QString &QString::replace(QLatin1String before, const QString &after, Qt::CaseSe */ QString &QString::replace(const QString &before, QLatin1String after, Qt::CaseSensitivity cs) { - int alen = after.size(); + qsizetype alen = after.size(); QVarLengthArray<char16_t> a(alen); qt_from_latin1(a.data(), after.latin1(), alen); return replace(before.constData(), before.d.size, (const QChar *)a.data(), alen, cs); @@ -3364,7 +3350,7 @@ QString &QString::replace(const QString &before, QLatin1String after, Qt::CaseSe */ QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) { - int alen = after.size(); + qsizetype alen = after.size(); QVarLengthArray<char16_t> a(alen); qt_from_latin1(a.data(), after.latin1(), alen); return replace(&c, 1, (const QChar *)a.data(), alen, cs); @@ -3722,7 +3708,7 @@ bool QString::operator>(QLatin1String other) const noexcept \sa lastIndexOf(), contains(), count() */ -int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const +qsizetype QString::indexOf(const QString &str, qsizetype from, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); @@ -3730,7 +3716,7 @@ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const #endif // QT_STRINGVIEW_LEVEL < 2 /*! - \fn int QString::indexOf(QStringView str, int from, Qt::CaseSensitivity cs) const + \fn qsizetype QString::indexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const \since 5.14 \overload indexOf() @@ -3766,7 +3752,7 @@ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const \sa lastIndexOf(), contains(), count() */ -int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const +qsizetype QString::indexOf(QLatin1String str, qsizetype from, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), size()), from, str, cs)); @@ -3779,7 +3765,7 @@ int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const character \a ch in the string, searching forward from index position \a from. Returns -1 if \a ch could not be found. */ -int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const +qsizetype QString::indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(qFindChar(QStringView(unicode(), length()), ch, from, cs)); @@ -3802,7 +3788,7 @@ int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const \sa indexOf(), contains(), count() */ -int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const +qsizetype QString::lastIndexOf(const QString &str, qsizetype from, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(QStringView(*this), from, str, cs)); @@ -3829,7 +3815,7 @@ int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) c \sa indexOf(), contains(), count() */ -int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const +qsizetype QString::lastIndexOf(QLatin1String str, qsizetype from, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); @@ -3841,14 +3827,14 @@ int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) co Returns the index position of the last occurrence of the character \a ch, searching backward from position \a from. */ -int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const +qsizetype QString::lastIndexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(qLastIndexOf(QStringView(*this), ch, from, cs)); } /*! - \fn int QString::lastIndexOf(QStringView str, int from, Qt::CaseSensitivity cs) const + \fn qsizetype QString::lastIndexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const \since 5.14 \overload lastIndexOf() @@ -3868,8 +3854,8 @@ int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const #if QT_CONFIG(regularexpression) struct QStringCapture { - int pos; - int len; + qsizetype pos; + qsizetype len; int no; }; Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE); @@ -3904,17 +3890,17 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) if (!iterator.hasNext()) // no matches at all return *this; - reallocData(uint(d.size) + 1u); + reallocData(size_t(d.size) + 1u); - int numCaptures = re.captureCount(); + qsizetype numCaptures = re.captureCount(); // 1. build the backreferences list, holding where the backreferences // are in the replacement string QList<QStringCapture> backReferences; - const int al = after.length(); + const qsizetype al = after.length(); const QChar *ac = after.unicode(); - for (int i = 0; i < al - 1; i++) { + for (qsizetype i = 0; i < al - 1; i++) { if (ac[i] == QLatin1Char('\\')) { int no = ac[i + 1].digitValue(); if (no > 0 && no <= numCaptures) { @@ -3940,12 +3926,12 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) // - the part before the match // - the after string, with the proper replacements for the backreferences - int newLength = 0; // length of the new string, with all the replacements - int lastEnd = 0; + qsizetype newLength = 0; // length of the new string, with all the replacements + qsizetype lastEnd = 0; QList<QStringRef> chunks; while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); - int len; + qsizetype len; // add the part before the match len = match.capturedStart() - lastEnd; if (len > 0) { @@ -3991,10 +3977,10 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) // 4. assemble the chunks together resize(newLength); - int i = 0; + qsizetype i = 0; QChar *uc = data(); for (const QStringRef &chunk : qAsConst(chunks)) { - int len = chunk.length(); + qsizetype len = chunk.length(); memcpy(uc + i, chunk.unicode(), len * sizeof(QChar)); i += len; } @@ -4013,7 +3999,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) \sa contains(), indexOf() */ -int QString::count(const QString &str, Qt::CaseSensitivity cs) const +qsizetype QString::count(const QString &str, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); @@ -4030,7 +4016,7 @@ int QString::count(const QString &str, Qt::CaseSensitivity cs) const \sa contains(), indexOf() */ -int QString::count(QChar ch, Qt::CaseSensitivity cs) const +qsizetype QString::count(QChar ch, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::count(QStringView(unicode(), size()), ch, cs)); @@ -4047,7 +4033,7 @@ int QString::count(QChar ch, Qt::CaseSensitivity cs) const \sa contains(), indexOf() */ -int QString::count(QStringView str, Qt::CaseSensitivity cs) const +qsizetype QString::count(QStringView str, Qt::CaseSensitivity cs) const { // ### Qt6: qsizetype return int(QtPrivate::count(*this, str, cs)); @@ -4129,7 +4115,7 @@ int QString::count(QStringView str, Qt::CaseSensitivity cs) const \snippet qstring/main.cpp 93 */ -int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const +qsizetype QString::indexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch) const { if (!re.isValid()) { qWarning("QString::indexOf: invalid QRegularExpression object"); @@ -4138,7 +4124,7 @@ int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionM QRegularExpressionMatch match = re.match(*this, from); if (match.hasMatch()) { - const int ret = match.capturedStart(); + const qsizetype ret = match.capturedStart(); if (rmatch) *rmatch = std::move(match); return ret; @@ -4162,19 +4148,19 @@ int QString::indexOf(const QRegularExpression &re, int from, QRegularExpressionM \snippet qstring/main.cpp 94 */ -int QString::lastIndexOf(const QRegularExpression &re, int from, QRegularExpressionMatch *rmatch) const +qsizetype QString::lastIndexOf(const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch) const { if (!re.isValid()) { qWarning("QString::lastIndexOf: invalid QRegularExpression object"); return -1; } - int endpos = (from < 0) ? (size() + from + 1) : (from + 1); + qsizetype endpos = (from < 0) ? (size() + from + 1) : (from + 1); QRegularExpressionMatchIterator iterator = re.globalMatch(*this); - int lastIndex = -1; + qsizetype lastIndex = -1; while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); - int start = match.capturedStart(); + qsizetype start = match.capturedStart(); if (start < endpos) { lastIndex = start; if (rmatch) @@ -4225,15 +4211,15 @@ bool QString::contains(const QRegularExpression &re, QRegularExpressionMatch *rm \snippet qstring/main.cpp 95 */ -int QString::count(const QRegularExpression &re) const +qsizetype QString::count(const QRegularExpression &re) const { if (!re.isValid()) { qWarning("QString::count: invalid QRegularExpression object"); return 0; } - int count = 0; - int index = -1; - int len = length(); + qsizetype count = 0; + qsizetype index = -1; + qsizetype len = length(); while (index < len - 1) { QRegularExpressionMatch match = re.match(*this, index + 1); if (!match.hasMatch()) @@ -4245,7 +4231,7 @@ int QString::count(const QRegularExpression &re) const } #endif // QT_CONFIG(regularexpression) -/*! \fn int QString::count() const +/*! \fn qsizetype QString::count() const \overload count() @@ -4281,7 +4267,7 @@ int QString::count(const QRegularExpression &re) const */ /*! - \fn QString QString::section(QChar sep, int start, int end = -1, SectionFlags flags) const + \fn QString QString::section(QChar sep, qsizetype start, qsizetype end = -1, SectionFlags flags) const This function returns a section of the string. @@ -4317,19 +4303,19 @@ int QString::count(const QRegularExpression &re) const \sa split() */ -QString QString::section(const QString &sep, int start, int end, SectionFlags flags) const +QString QString::section(const QString &sep, qsizetype start, qsizetype end, SectionFlags flags) const { const QList<QStringRef> sections = splitRef( sep, Qt::KeepEmptyParts, (flags & SectionCaseInsensitiveSeps) ? Qt::CaseInsensitive : Qt::CaseSensitive); - const int sectionsSize = sections.size(); + const qsizetype sectionsSize = sections.size(); if (!(flags & SectionSkipEmpty)) { if (start < 0) start += sectionsSize; if (end < 0) end += sectionsSize; } else { - int skip = 0; - for (int k = 0; k < sectionsSize; ++k) { + qsizetype skip = 0; + for (qsizetype k = 0; k < sectionsSize; ++k) { if (sections.at(k).isEmpty()) skip++; } @@ -4342,8 +4328,8 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl return QString(); QString ret; - int first_i = start, last_i = end; - for (int x = 0, i = 0; x <= end && i < sectionsSize; ++i) { + qsizetype first_i = start, last_i = end; + for (qsizetype x = 0, i = 0; x <= end && i < sectionsSize; ++i) { const QStringRef §ion = sections.at(i); const bool empty = section.isEmpty(); if (x >= start) { @@ -4369,15 +4355,16 @@ QString QString::section(const QString &sep, int start, int end, SectionFlags fl class qt_section_chunk { public: qt_section_chunk() {} - qt_section_chunk(int l, QStringRef s) : length(l), string(std::move(s)) {} - int length; + qt_section_chunk(qsizetype l, QStringRef s) : length(l), string(std::move(s)) {} + qsizetype length; QStringRef string; }; Q_DECLARE_TYPEINFO(qt_section_chunk, Q_MOVABLE_TYPE); -static QString extractSections(const QList<qt_section_chunk> §ions, int start, int end, QString::SectionFlags flags) +static QString extractSections(const QList<qt_section_chunk> §ions, qsizetype start, qsizetype end, + QString::SectionFlags flags) { - const int sectionsSize = sections.size(); + const qsizetype sectionsSize = sections.size(); if (!(flags & QString::SectionSkipEmpty)) { if (start < 0) @@ -4385,8 +4372,8 @@ static QString extractSections(const QList<qt_section_chunk> §ions, int star if (end < 0) end += sectionsSize; } else { - int skip = 0; - for (int k = 0; k < sectionsSize; ++k) { + qsizetype skip = 0; + for (qsizetype k = 0; k < sectionsSize; ++k) { const qt_section_chunk §ion = sections.at(k); if (section.length == section.string.length()) skip++; @@ -4400,9 +4387,9 @@ static QString extractSections(const QList<qt_section_chunk> §ions, int star return QString(); QString ret; - int x = 0; - int first_i = start, last_i = end; - for (int i = 0; x <= end && i < sectionsSize; ++i) { + qsizetype x = 0; + qsizetype first_i = start, last_i = end; + for (qsizetype i = 0; x <= end && i < sectionsSize; ++i) { const qt_section_chunk §ion = sections.at(i); const bool empty = (section.length == section.string.length()); if (x >= start) { @@ -4449,7 +4436,7 @@ static QString extractSections(const QList<qt_section_chunk> §ions, int star \sa split(), simplified() */ -QString QString::section(const QRegularExpression &re, int start, int end, SectionFlags flags) const +QString QString::section(const QRegularExpression &re, qsizetype start, qsizetype end, SectionFlags flags) const { if (!re.isValid()) { qWarning("QString::section: invalid QRegularExpression object"); @@ -4465,7 +4452,7 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti sep.setPatternOptions(sep.patternOptions() | QRegularExpression::CaseInsensitiveOption); QList<qt_section_chunk> sections; - int n = length(), m = 0, last_m = 0, last_len = 0; + qsizetype n = length(), m = 0, last_m = 0, last_len = 0; QRegularExpressionMatchIterator iterator = sep.globalMatch(*this); while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); @@ -4493,9 +4480,9 @@ QString QString::section(const QRegularExpression &re, int start, int end, Secti \sa first(), last(), startsWith(), chopped(), chop(), truncate() */ -QString QString::left(int n) const +QString QString::left(qsizetype n) const { - if (uint(n) >= uint(size())) + if (size_t(n) >= size_t(size())) return *this; return QString((const QChar*) d.data(), n); } @@ -4513,9 +4500,9 @@ QString QString::left(int n) const \sa endsWith(), last(), first(), sliced(), chopped(), chop(), truncate() */ -QString QString::right(int n) const +QString QString::right(qsizetype n) const { - if (uint(n) >= uint(size())) + if (size_t(n) >= size_t(size())) return *this; return QString(constData() + size() - n, n); } @@ -4539,7 +4526,7 @@ QString QString::right(int n) const \sa first(), last(), sliced(), chopped(), chop(), truncate() */ -QString QString::mid(int position, int n) const +QString QString::mid(qsizetype position, qsizetype n) const { qsizetype p = position; qsizetype l = n; @@ -4607,7 +4594,7 @@ QString QString::mid(int position, int n) const */ /*! - \fn QString QString::chopped(int len) const + \fn QString QString::chopped(qsizetype len) const \since 5.10 Returns a string that contains the size() - \a len leftmost characters @@ -4817,7 +4804,7 @@ QByteArray QString::toLatin1_helper_inplace(QString &s) // We can return our own buffer to the caller. // Conversion to Latin-1 always shrinks the buffer by half. const char16_t *data = s.d.data(); - int length = s.d.size; + qsizetype length = s.d.size; // Move the d pointer over to the bytearray. // Kids, avert your eyes. Don't try this at home. @@ -4870,7 +4857,7 @@ static QByteArray qt_convert_to_local_8bit(QStringView string); \sa fromLocal8Bit(), toLatin1(), toUtf8(), QStringEncoder */ -QByteArray QString::toLocal8Bit_helper(const QChar *data, int size) +QByteArray QString::toLocal8Bit_helper(const QChar *data, qsizetype size) { return qt_convert_to_local_8bit(QStringView(data, size)); } @@ -5000,7 +4987,7 @@ QList<uint> QtPrivate::convertToUcs4(QStringView string) return qt_convert_to_ucs4(string); } -QString::DataPointer QString::fromLatin1_helper(const char *str, int size) +QString::DataPointer QString::fromLatin1_helper(const char *str, qsizetype size) { DataPointer d; if (!str) { @@ -5014,12 +5001,12 @@ QString::DataPointer QString::fromLatin1_helper(const char *str, int size) d.data()[size] = '\0'; char16_t *dst = d.data(); - qt_from_latin1(dst, str, uint(size)); + qt_from_latin1(dst, str, size_t(size)); } return d; } -/*! \fn QString QString::fromLatin1(const char *str, int size) +/*! \fn QString QString::fromLatin1(const char *str, qsizetype size) Returns a QString initialized with the first \a size characters of the Latin-1 string \a str. @@ -5037,7 +5024,7 @@ QString::DataPointer QString::fromLatin1_helper(const char *str, int size) Returns a QString initialized with the Latin-1 string \a str. */ -/*! \fn QString QString::fromLocal8Bit(const char *str, int size) +/*! \fn QString QString::fromLocal8Bit(const char *str, qsizetype size) Returns a QString initialized with the first \a size characters of the 8-bit string \a str. @@ -5057,7 +5044,7 @@ QString::DataPointer QString::fromLatin1_helper(const char *str, int size) Returns a QString initialized with the 8-bit string \a str. */ -QString QString::fromLocal8Bit_helper(const char *str, int size) +QString QString::fromLocal8Bit_helper(const char *str, qsizetype size) { if (!str) return QString(); @@ -5069,7 +5056,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) return toUtf16(str, size); } -/*! \fn QString QString::fromUtf8(const char *str, int size) +/*! \fn QString QString::fromUtf8(const char *str, qsizetype size) Returns a QString initialized with the first \a size bytes of the UTF-8 string \a str. @@ -5106,7 +5093,7 @@ QString QString::fromLocal8Bit_helper(const char *str, int size) Returns a QString initialized with the UTF-8 string \a str. */ -QString QString::fromUtf8_helper(const char *str, int size) +QString QString::fromUtf8_helper(const char *str, qsizetype size) { if (!str) return QString(); @@ -5132,7 +5119,7 @@ QString QString::fromUtf8_helper(const char *str, int size) \sa utf16(), setUtf16(), fromStdU16String() */ -QString QString::fromUtf16(const char16_t *unicode, int size) +QString QString::fromUtf16(const char16_t *unicode, qsizetype size) { if (!unicode) return QString(); @@ -5146,14 +5133,14 @@ QString QString::fromUtf16(const char16_t *unicode, int size) } /*! - \fn QString QString::fromUtf16(const ushort *str, int size) + \fn QString QString::fromUtf16(const ushort *str, qsizetype size) \obsolete Use the \c char16_t overload. */ /*! - \fn QString QString::fromUcs4(const uint *str, int size) + \fn QString QString::fromUcs4(const uint *str, qsizetype size) \since 4.2 \obsolete @@ -5170,7 +5157,7 @@ QString QString::fromUtf16(const char16_t *unicode, int size) \sa toUcs4(), fromUtf16(), utf16(), setUtf16(), fromWCharArray(), fromStdU32String() */ -QString QString::fromUcs4(const char32_t *unicode, int size) +QString QString::fromUcs4(const char32_t *unicode, qsizetype size) { if (!unicode) return QString(); @@ -5193,7 +5180,7 @@ QString QString::fromUcs4(const char32_t *unicode, int size) \sa unicode(), setUtf16() */ -QString& QString::setUnicode(const QChar *unicode, int size) +QString& QString::setUnicode(const QChar *unicode, qsizetype size) { resize(size); if (unicode && size) @@ -5202,7 +5189,7 @@ QString& QString::setUnicode(const QChar *unicode, int size) } /*! - \fn QString &QString::setUtf16(const ushort *unicode, int size) + \fn QString &QString::setUtf16(const ushort *unicode, qsizetype size) Resizes the string to \a size characters and copies \a unicode into the string. @@ -5307,7 +5294,7 @@ QString QString::trimmed_helper(QString &str) return QStringAlgorithms<QString>::trimmed_helper(str); } -/*! \fn const QChar QString::at(int position) const +/*! \fn const QChar QString::at(qsizetype position) const Returns the character at the given index \a position in the string. @@ -5319,7 +5306,7 @@ QString QString::trimmed_helper(QString &str) */ /*! - \fn QChar &QString::operator[](int position) + \fn QChar &QString::operator[](qsizetype position) Returns the character at the specified \a position in the string as a modifiable reference. @@ -5332,7 +5319,7 @@ QString QString::trimmed_helper(QString &str) */ /*! - \fn const QChar QString::operator[](int position) const + \fn const QChar QString::operator[](qsizetype position) const \overload operator[]() */ @@ -5398,7 +5385,7 @@ QString QString::trimmed_helper(QString &str) */ /*! - \fn void QString::truncate(int position) + \fn void QString::truncate(qsizetype position) Truncates the string at the given \a position index. @@ -5414,7 +5401,7 @@ QString QString::trimmed_helper(QString &str) \sa chop(), resize(), left(), QStringRef::truncate() */ -void QString::truncate(int pos) +void QString::truncate(qsizetype pos) { if (pos < size()) resize(pos); @@ -5435,7 +5422,7 @@ void QString::truncate(int pos) \sa truncate(), resize(), remove(), QStringRef::chop() */ -void QString::chop(int n) +void QString::chop(qsizetype n) { if (n > 0) resize(d.size - n); @@ -5453,7 +5440,7 @@ void QString::chop(int n) \sa resize() */ -QString& QString::fill(QChar ch, int size) +QString& QString::fill(QChar ch, qsizetype size) { resize(size < 0 ? d.size : size); if (d.size) { @@ -5466,7 +5453,7 @@ QString& QString::fill(QChar ch, int size) } /*! - \fn int QString::length() const + \fn qsizetype QString::length() const Returns the number of characters in this string. Equivalent to size(). @@ -5475,7 +5462,7 @@ QString& QString::fill(QChar ch, int size) */ /*! - \fn int QString::size() const + \fn qsizetype QString::size() const Returns the number of characters in this string. @@ -5782,7 +5769,7 @@ int QString::compare(const QString &other, Qt::CaseSensitivity cs) const noexcep \internal \since 4.5 */ -int QString::compare_helper(const QChar *data1, int length1, const QChar *data2, int length2, +int QString::compare_helper(const QChar *data1, qsizetype length1, const QChar *data2, qsizetype length2, Qt::CaseSensitivity cs) noexcept { Q_ASSERT(length1 >= 0); @@ -5807,7 +5794,7 @@ int QString::compare(QLatin1String other, Qt::CaseSensitivity cs) const noexcept \internal \since 5.0 */ -int QString::compare_helper(const QChar *data1, int length1, const char *data2, int length2, +int QString::compare_helper(const QChar *data1, qsizetype length1, const char *data2, qsizetype length2, Qt::CaseSensitivity cs) { Q_ASSERT(length1 >= 0); @@ -5837,7 +5824,7 @@ int QString::compare_helper(const QChar *data1, int length1, const char *data2, \internal \since 4.5 */ -int QString::compare_helper(const QChar *data1, int length1, QLatin1String s2, +int QString::compare_helper(const QChar *data1, qsizetype length1, QLatin1String s2, Qt::CaseSensitivity cs) noexcept { Q_ASSERT(length1 >= 0); @@ -5925,8 +5912,8 @@ Q_GLOBAL_STATIC(QThreadStorage<QCollator>, defaultCollator) \internal \since 4.5 */ -int QString::localeAwareCompare_helper(const QChar *data1, int length1, - const QChar *data2, int length2) +int QString::localeAwareCompare_helper(const QChar *data1, qsizetype length1, + const QChar *data2, qsizetype length2) { Q_ASSERT(length1 >= 0); Q_ASSERT(data1 || length1 == 0); @@ -6013,7 +6000,7 @@ const ushort *QString::utf16() const { if (!d->isMutable()) { // ensure '\0'-termination for ::fromRawData strings - const_cast<QString*>(this)->reallocData(uint(d.size) + 1u); + const_cast<QString*>(this)->reallocData(size_t(d.size) + 1u); } return reinterpret_cast<const ushort *>(d.data()); } @@ -6036,11 +6023,11 @@ const ushort *QString::utf16() const \sa rightJustified() */ -QString QString::leftJustified(int width, QChar fill, bool truncate) const +QString QString::leftJustified(qsizetype width, QChar fill, bool truncate) const { QString result; - int len = length(); - int padlen = width - len; + qsizetype len = length(); + qsizetype padlen = width - len; if (padlen > 0) { result.resize(len+padlen); if (len) @@ -6075,11 +6062,11 @@ QString QString::leftJustified(int width, QChar fill, bool truncate) const \sa leftJustified() */ -QString QString::rightJustified(int width, QChar fill, bool truncate) const +QString QString::rightJustified(qsizetype width, QChar fill, bool truncate) const { QString result; - int len = length(); - int padlen = width - len; + qsizetype len = length(); + qsizetype padlen = width - len; if (padlen > 0) { result.resize(len+padlen); QChar *uc = (QChar*)result.d.data(); @@ -6153,8 +6140,8 @@ static QString detachAndConvertCase(T &str, QStringIterator it, QUnicodeTables:: *pp++ = folded.chars[1]; } else { // slow path: the string is growing - int inpos = it.index() - 1; - int outpos = pp - s.constBegin(); + qsizetype inpos = it.index() - 1; + qsizetype outpos = pp - s.constBegin(); s.replace(outpos, 1, reinterpret_cast<const QChar *>(folded.data()), folded.size()); pp = const_cast<QChar *>(s.constBegin()) + outpos + folded.size(); @@ -7323,8 +7310,8 @@ static ResultList splitString(const String &source, const QRegularExpression &re return list; } - int start = 0; - int end = 0; + qsizetype start = 0; + qsizetype end = 0; QRegularExpressionMatchIterator iterator = re.globalMatch(source); while (iterator.hasNext()) { QRegularExpressionMatch match = iterator.next(); @@ -7437,7 +7424,7 @@ QList<QStringView> QStringView::split(const QRegularExpression &re, Qt::SplitBeh \snippet code/src_corelib_text_qstring.cpp 8 */ -QString QString::repeated(int times) const +QString QString::repeated(qsizetype times) const { if (d.size == 0) return *this; @@ -7448,7 +7435,7 @@ QString QString::repeated(int times) const return QString(); } - const int resultSize = times * d.size; + const qsizetype resultSize = times * d.size; QString result; result.reserve(resultSize); @@ -7457,10 +7444,10 @@ QString QString::repeated(int times) const memcpy(result.d.data(), d.data(), d.size * sizeof(QChar)); - int sizeSoFar = d.size; + qsizetype sizeSoFar = d.size; char16_t *end = result.d.data() + sizeSoFar; - const int halfResultSize = resultSize >> 1; + const qsizetype halfResultSize = resultSize >> 1; while (sizeSoFar <= halfResultSize) { memcpy(end, result.d.data(), sizeSoFar * sizeof(QChar)); end += sizeSoFar; @@ -7472,7 +7459,7 @@ QString QString::repeated(int times) const return result; } -void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, int from) +void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar::UnicodeVersion version, qsizetype from) { const QChar *p = data->constData() + from; if (isAscii(p, p + data->length() - from)) @@ -7488,7 +7475,7 @@ void qt_string_normalize(QString *data, QString::NormalizationForm mode, QChar:: for (int i = 0; i < NumNormalizationCorrections; ++i) { const NormalizationCorrection &n = uc_normalization_corrections[i]; if (n.version > version) { - int pos = from; + qsizetype pos = from; if (QChar::requiresSurrogates(n.ucs4)) { char16_t ucs4High = QChar::highSurrogate(n.ucs4); char16_t ucs4Low = QChar::lowSurrogate(n.ucs4); @@ -7620,7 +7607,7 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, int fiel const QChar *uc_end = s.end(); int abs_field_width = qAbs(field_width); - int result_len = s.length() + qsizetype result_len = s.length() - d.escape_len + (d.occurrences - d.locale_occurrences) *qMax(abs_field_width, arg.length()) @@ -8612,7 +8599,7 @@ bool QString::isRightToLeft() const \sa fromUtf16(), setRawData() */ -QString QString::fromRawData(const QChar *unicode, int size) +QString QString::fromRawData(const QChar *unicode, qsizetype size) { return QString(DataPointer::fromRawData(const_cast<char16_t *>(reinterpret_cast<const char16_t *>(unicode)), size)); } @@ -8631,7 +8618,7 @@ QString QString::fromRawData(const QChar *unicode, int size) \sa fromRawData() */ -QString &QString::setRawData(const QChar *unicode, int size) +QString &QString::setRawData(const QChar *unicode, qsizetype size) { if (!unicode || !size) { clear(); @@ -8745,14 +8732,14 @@ QString &QString::setRawData(const QChar *unicode, int size) \typedef QLatin1String::difference_type \since 5.10 - Alias for \c{int}. Provided for compatibility with the STL. + Alias for \c{qsizetype}. Provided for compatibility with the STL. */ /*! \typedef QLatin1String::size_type \since 5.10 - Alias for \c{int}. Provided for compatibility with the STL. + Alias for \c{qsizetype}. Provided for compatibility with the STL. */ /*! diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 2db2e8cb85..f3222155b8 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -276,9 +276,9 @@ public: typedef QStringPrivate DataPointer; inline constexpr QString() noexcept; - explicit QString(const QChar *unicode, int size = -1); + explicit QString(const QChar *unicode, qsizetype size = -1); QString(QChar c); - QString(int size, QChar c); + QString(qsizetype size, QChar c); inline QString(QLatin1String latin1); inline QString(const QString &) noexcept; inline ~QString(); @@ -290,19 +290,19 @@ public: inline QString &operator=(QString &&other) noexcept { qSwap(d, other.d); return *this; } inline void swap(QString &other) noexcept { qSwap(d, other.d); } - inline int size() const { return int(d.size); } - inline int count() const { return int(d.size); } - inline int length() const; + inline qsizetype size() const { return d.size; } + inline qsizetype count() const { return d.size; } + inline qsizetype length() const { return d.size; } inline bool isEmpty() const; - void resize(int size); - void resize(int size, QChar fillChar); + void resize(qsizetype size); + void resize(qsizetype size, QChar fillChar); - QString &fill(QChar c, int size = -1); - void truncate(int pos); - void chop(int n); + QString &fill(QChar c, qsizetype size = -1); + void truncate(qsizetype pos); + void chop(qsizetype n); - inline int capacity() const; - inline void reserve(int size); + inline qsizetype capacity() const; + inline void reserve(qsizetype size); inline void squeeze(); inline const QChar *unicode() const; @@ -315,9 +315,9 @@ public: inline bool isSharedWith(const QString &other) const { return d.isSharedWith(other.d); } void clear(); - inline const QChar at(int i) const; - const QChar operator[](int i) const; - Q_REQUIRED_RESULT QChar &operator[](int i); + inline const QChar at(qsizetype i) const; + const QChar operator[](qsizetype i) const; + Q_REQUIRED_RESULT QChar &operator[](qsizetype i); Q_REQUIRED_RESULT inline QChar front() const { return at(0); } Q_REQUIRED_RESULT inline QChar &front(); @@ -384,20 +384,20 @@ public: static QString vasprintf(const char *format, va_list ap) Q_ATTRIBUTE_FORMAT_PRINTF(1, 0); static QString asprintf(const char *format, ...) Q_ATTRIBUTE_FORMAT_PRINTF(1, 2); - int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int indexOf(QLatin1String s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + qsizetype indexOf(QChar c, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + qsizetype indexOf(QLatin1String s, qsizetype 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; + qsizetype indexOf(const QString &s, qsizetype 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 - int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; - int lastIndexOf(QLatin1String s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + Q_REQUIRED_RESULT qsizetype indexOf(QStringView s, qsizetype from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept + { return QtPrivate::findString(*this, from, s, cs); } + qsizetype lastIndexOf(QChar c, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + qsizetype lastIndexOf(QLatin1String s, qsizetype 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; + qsizetype lastIndexOf(const QString &s, qsizetype 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 + Q_REQUIRED_RESULT qsizetype lastIndexOf(QStringView s, qsizetype from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsizetype inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; @@ -406,17 +406,17 @@ public: #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(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + qsizetype count(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + qsizetype count(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + qsizetype count(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_CONFIG(regularexpression) - int indexOf(const QRegularExpression &re, int from = 0, - QRegularExpressionMatch *rmatch = nullptr) const; - int lastIndexOf(const QRegularExpression &re, int from = -1, - QRegularExpressionMatch *rmatch = nullptr) const; + qsizetype indexOf(const QRegularExpression &re, qsizetype from = 0, + QRegularExpressionMatch *rmatch = nullptr) const; + qsizetype lastIndexOf(const QRegularExpression &re, qsizetype from = -1, + QRegularExpressionMatch *rmatch = nullptr) const; bool contains(const QRegularExpression &re, QRegularExpressionMatch *rmatch = nullptr) const; - int count(const QRegularExpression &re) const; + qsizetype count(const QRegularExpression &re) const; #endif enum SectionFlag { @@ -428,24 +428,24 @@ public: }; Q_DECLARE_FLAGS(SectionFlags, SectionFlag) - QString section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; - QString section(const QString &in_sep, int start, int end = -1, SectionFlags flags = SectionDefault) const; + QString section(QChar sep, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const; + QString section(const QString &in_sep, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const; #if QT_CONFIG(regularexpression) - QString section(const QRegularExpression &re, int start, int end = -1, SectionFlags flags = SectionDefault) const; + QString section(const QRegularExpression &re, qsizetype start, qsizetype end = -1, SectionFlags flags = SectionDefault) const; #endif - Q_REQUIRED_RESULT QString left(int n) const; - Q_REQUIRED_RESULT QString right(int n) const; - Q_REQUIRED_RESULT QString mid(int position, int n = -1) const; + Q_REQUIRED_RESULT QString left(qsizetype n) const; + Q_REQUIRED_RESULT QString right(qsizetype n) const; + Q_REQUIRED_RESULT QString mid(qsizetype position, qsizetype n = -1) const; Q_REQUIRED_RESULT QString first(qsizetype n) const - { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data(), int(n)); } + { 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, int(n)); } + { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return QString(data() + size() - n, 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_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, int(n)); } - Q_REQUIRED_RESULT QString chopped(int 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); } + Q_REQUIRED_RESULT QString chopped(qsizetype n) const { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); return first(size() - n); } @@ -472,8 +472,8 @@ public: bool isUpper() const; bool isLower() const; - Q_REQUIRED_RESULT QString leftJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const; - Q_REQUIRED_RESULT QString rightJustified(int width, QChar fill = QLatin1Char(' '), bool trunc = false) const; + Q_REQUIRED_RESULT QString leftJustified(qsizetype width, QChar fill = QLatin1Char(' '), bool trunc = false) const; + Q_REQUIRED_RESULT QString rightJustified(qsizetype width, QChar fill = QLatin1Char(' '), bool trunc = false) const; #if defined(Q_COMPILER_REF_QUALIFIERS) && !defined(QT_COMPILING_QSTRING_COMPAT_CPP) && !defined(Q_CLANG_QDOC) # if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !__has_cpp_attribute(nodiscard) @@ -515,16 +515,16 @@ public: #endif Q_REQUIRED_RESULT QString toHtmlEscaped() const; - QString &insert(int i, QChar c); - QString &insert(int i, const QChar *uc, int len); + QString &insert(qsizetype i, QChar c); + QString &insert(qsizetype i, const QChar *uc, qsizetype len); #if QT_STRINGVIEW_LEVEL < 2 - inline QString &insert(int i, const QString &s) { return insert(i, s.constData(), s.length()); } + inline QString &insert(qsizetype i, const QString &s) { return insert(i, s.constData(), s.length()); } #endif - inline QString &insert(int i, QStringView v) { return insert(i, v.data(), v.length()); } - QString &insert(int i, QLatin1String s); + inline QString &insert(qsizetype i, QStringView v) { return insert(i, v.data(), v.length()); } + QString &insert(qsizetype i, QLatin1String s); QString &append(QChar c); - QString &append(const QChar *uc, int len); + QString &append(const QChar *uc, qsizetype len); #if QT_STRINGVIEW_LEVEL < 2 QString &append(const QString &s); #endif @@ -532,7 +532,7 @@ public: QString &append(QLatin1String s); inline QString &prepend(QChar c) { return insert(0, c); } - inline QString &prepend(const QChar *uc, int len) { return insert(0, uc, len); } + inline QString &prepend(const QChar *uc, qsizetype len) { return insert(0, uc, len); } #if QT_STRINGVIEW_LEVEL < 2 inline QString &prepend(const QString &s) { return insert(0, s); } #endif @@ -553,15 +553,15 @@ public: inline QString &operator+=(QStringView v) { return append(v); } inline QString &operator+=(QLatin1String s) { return append(s); } - QString &remove(int i, int len); + QString &remove(qsizetype i, qsizetype len); QString &remove(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &remove(QLatin1String s, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &remove(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive); - QString &replace(int i, int len, QChar after); - QString &replace(int i, int len, const QChar *s, int slen); - QString &replace(int i, int len, const QString &after); + QString &replace(qsizetype i, qsizetype len, QChar after); + QString &replace(qsizetype i, qsizetype len, const QChar *s, qsizetype slen); + QString &replace(qsizetype i, qsizetype len, const QString &after); QString &replace(QChar before, QChar after, Qt::CaseSensitivity cs = Qt::CaseSensitive); - QString &replace(const QChar *before, int blen, const QChar *after, int alen, Qt::CaseSensitivity cs = Qt::CaseSensitive); + QString &replace(const QChar *before, qsizetype blen, const QChar *after, qsizetype alen, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(QLatin1String before, QLatin1String after, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(QLatin1String before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); QString &replace(const QString &before, QLatin1String after, Qt::CaseSensitivity cs = Qt::CaseSensitive); @@ -623,7 +623,7 @@ public: }; Q_REQUIRED_RESULT QString normalized(NormalizationForm mode, QChar::UnicodeVersion version = QChar::Unicode_Unassigned) const; - Q_REQUIRED_RESULT QString repeated(int times) const; + Q_REQUIRED_RESULT QString repeated(qsizetype times) const; const ushort *utf16() const; @@ -648,22 +648,22 @@ public: Q_REQUIRED_RESULT QList<uint> toUcs4() const; // note - this are all inline so we can benefit from strlen() compile time optimizations - static inline QString fromLatin1(const char *str, int size = -1) + static inline QString fromLatin1(const char *str, qsizetype size = -1) { - return QString(fromLatin1_helper(str, (str && size == -1) ? int(strlen(str)) : size)); + return QString(fromLatin1_helper(str, (str && size == -1) ? qsizetype(strlen(str)) : size)); } - static inline QString fromUtf8(const char *str, int size = -1) + static inline QString fromUtf8(const char *str, qsizetype size = -1) { - return fromUtf8_helper(str, (str && size == -1) ? int(strlen(str)) : size); + return fromUtf8_helper(str, (str && size == -1) ? qsizetype(strlen(str)) : size); } #ifdef __cpp_char8_t Q_WEAK_OVERLOAD static inline QString fromUtf8(const char8_t *str, qsizetype size = -1) { return fromUtf8(reinterpret_cast<const char *>(str), int(size)); } #endif - static inline QString fromLocal8Bit(const char *str, int size = -1) + static inline QString fromLocal8Bit(const char *str, qsizetype size = -1) { - return fromLocal8Bit_helper(str, (str && size == -1) ? int(strlen(str)) : size); + return fromLocal8Bit_helper(str, (str && size == -1) ? qsizetype(strlen(str)) : size); } static inline QString fromLatin1(const QByteArray &str) { return str.isNull() ? QString() : fromLatin1(str.data(), qstrnlen(str.constData(), str.size())); } @@ -671,25 +671,25 @@ public: { return str.isNull() ? QString() : fromUtf8(str.data(), qstrnlen(str.constData(), str.size())); } static inline QString fromLocal8Bit(const QByteArray &str) { return str.isNull() ? QString() : fromLocal8Bit(str.data(), qstrnlen(str.constData(), str.size())); } - static QString fromUtf16(const char16_t *, int size = -1); - static QString fromUcs4(const char32_t *, int size = -1); - static QString fromRawData(const QChar *, int size); + static QString fromUtf16(const char16_t *, qsizetype size = -1); + static QString fromUcs4(const char32_t *, qsizetype size = -1); + static QString fromRawData(const QChar *, qsizetype size); #if QT_DEPRECATED_SINCE(6, 0) QT_DEPRECATED_VERSION_X_6_0("Use char16_t* overload.") - static QString fromUtf16(const ushort *str, int size = -1) + static QString fromUtf16(const ushort *str, qsizetype size = -1) { return fromUtf16(reinterpret_cast<const char16_t *>(str), size); } QT_DEPRECATED_VERSION_X_6_0("Use char32_t* overload.") - static QString fromUcs4(const uint *str, int size = -1) + static QString fromUcs4(const uint *str, qsizetype size = -1) { return fromUcs4(reinterpret_cast<const char32_t *>(str), size); } #endif - inline int toWCharArray(wchar_t *array) const; - Q_REQUIRED_RESULT static inline QString fromWCharArray(const wchar_t *string, int size = -1); + inline qsizetype toWCharArray(wchar_t *array) const; + Q_REQUIRED_RESULT static inline QString fromWCharArray(const wchar_t *string, qsizetype size = -1); - QString &setRawData(const QChar *unicode, int size); - QString &setUnicode(const QChar *unicode, int size); - inline QString &setUtf16(const ushort *utf16, int size); + QString &setRawData(const QChar *unicode, qsizetype size); + QString &setUnicode(const QChar *unicode, qsizetype size); + inline QString &setUtf16(const ushort *utf16, qsizetype size); #if QT_STRINGVIEW_LEVEL < 2 int compare(const QString &s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; @@ -768,16 +768,16 @@ public: // ASCII compatibility #if defined(QT_RESTRICTED_CAST_FROM_ASCII) - template <int N> + template <qsizetype N> inline QString(const char (&ch)[N]) : QString(fromUtf8(ch)) {} - template <int N> + template <qsizetype N> QString(char (&)[N]) = delete; - template <int N> + template <qsizetype N> inline QString &operator=(const char (&ch)[N]) { return (*this = fromUtf8(ch, N - 1)); } - template <int N> + template <qsizetype N> QString &operator=(char (&)[N]) = delete; #endif #if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) @@ -801,9 +801,9 @@ public: { return append(QString::fromUtf8(s)); } inline QT_ASCII_CAST_WARN QString &append(const QByteArray &s) { return append(QString::fromUtf8(s)); } - inline QT_ASCII_CAST_WARN QString &insert(int i, const char *s) + inline QT_ASCII_CAST_WARN QString &insert(qsizetype i, const char *s) { return insert(i, QString::fromUtf8(s)); } - inline QT_ASCII_CAST_WARN QString &insert(int i, const QByteArray &s) + inline QT_ASCII_CAST_WARN QString &insert(qsizetype i, const QByteArray &s) { return insert(i, QString::fromUtf8(s)); } inline QT_ASCII_CAST_WARN QString &operator+=(const char *s) { return append(QString::fromUtf8(s)); } @@ -861,7 +861,7 @@ public: const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } // STL compatibility - typedef int size_type; + typedef qsizetype size_type; typedef qptrdiff difference_type; typedef const QChar & const_reference; typedef QChar & reference; @@ -901,7 +901,7 @@ public: Q_REQUIRED_RESULT bool isValidUtf16() const noexcept { return QStringView(*this).isValidUtf16(); } - QString(int size, Qt::Initialization); + QString(qsizetype size, Qt::Initialization); explicit QString(DataPointer &&dd) : d(std::move(dd)) {} private: @@ -927,21 +927,21 @@ private: friend inline bool operator< (QChar, QLatin1String) noexcept; friend inline bool operator> (QChar, QLatin1String) noexcept; - void reallocData(uint alloc, bool grow = false); + void reallocData(size_t alloc, bool grow = false); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void expand(int i); #endif - static int compare_helper(const QChar *data1, int length1, - const QChar *data2, int length2, + static int compare_helper(const QChar *data1, qsizetype length1, + const QChar *data2, qsizetype length2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - static int compare_helper(const QChar *data1, int length1, - const char *data2, int length2, + static int compare_helper(const QChar *data1, qsizetype length1, + const char *data2, qsizetype length2, Qt::CaseSensitivity cs = Qt::CaseSensitive); - static int compare_helper(const QChar *data1, int length1, + static int compare_helper(const QChar *data1, qsizetype length1, QLatin1String s2, Qt::CaseSensitivity cs = Qt::CaseSensitive) noexcept; - static int localeAwareCompare_helper(const QChar *data1, int length1, - const QChar *data2, int length2); + static int localeAwareCompare_helper(const QChar *data1, qsizetype length1, + const QChar *data2, qsizetype length2); static QString toLower_helper(const QString &str); static QString toLower_helper(QString &str); static QString toUpper_helper(const QString &str); @@ -952,17 +952,17 @@ private: static QString trimmed_helper(QString &str); static QString simplified_helper(const QString &str); static QString simplified_helper(QString &str); - static DataPointer fromLatin1_helper(const char *str, int size = -1); - static QString fromUtf8_helper(const char *str, int size); - static QString fromLocal8Bit_helper(const char *, int size); + static DataPointer fromLatin1_helper(const char *str, qsizetype size = -1); + static QString fromUtf8_helper(const char *str, qsizetype size); + static QString fromLocal8Bit_helper(const char *, qsizetype size); static QByteArray toLatin1_helper(const QString &); static QByteArray toLatin1_helper_inplace(QString &); static QByteArray toUtf8_helper(const QString &); - static QByteArray toLocal8Bit_helper(const QChar *data, int size); - static int toUcs4_helper(const ushort *uc, int length, uint *out); + static QByteArray toLocal8Bit_helper(const QChar *data, qsizetype size); + static qsizetype toUcs4_helper(const ushort *uc, qsizetype length, uint *out); static qlonglong toIntegral_helper(QStringView string, bool *ok, int base); static qulonglong toIntegral_helper(QStringView string, bool *ok, uint base); - void replace_helper(uint *indices, int nIndices, int blen, const QChar *after, int alen); + void replace_helper(size_t *indices, qsizetype nIndices, qsizetype blen, const QChar *after, qsizetype alen); friend class QStringRef; friend class QStringView; friend class QByteArray; @@ -1023,12 +1023,10 @@ ushort QStringView::toUShort(bool *ok, int base) const // inline QString::QString(QLatin1String aLatin1) : d(fromLatin1_helper(aLatin1.latin1(), aLatin1.size())) { } -inline int QString::length() const -{ return int(d.size); } -inline const QChar QString::at(int i) const -{ Q_ASSERT(uint(i) < uint(size())); return QChar(d.data()[i]); } -inline const QChar QString::operator[](int i) const -{ Q_ASSERT(uint(i) < uint(size())); return QChar(d.data()[i]); } +inline const QChar QString::at(qsizetype i) const +{ Q_ASSERT(size_t(i) < size_t(size())); return QChar(d.data()[i]); } +inline const QChar QString::operator[](qsizetype i) const +{ Q_ASSERT(size_t(i) < size_t(size())); return QChar(d.data()[i]); } inline bool QString::isEmpty() const { return d.size == 0; } inline const QChar *QString::unicode() const @@ -1057,7 +1055,7 @@ inline void QString::clear() { if (!isNull()) *this = QString(); } inline QString::QString(const QString &other) noexcept : d(other.d) { } -inline int QString::capacity() const +inline qsizetype QString::capacity() const { const auto realCapacity = d->constAllocatedCapacity(); return realCapacity ? int(realCapacity) - 1 : 0; } inline QString &QString::setNum(short n, int base) { return setNum(qlonglong(n), base); } @@ -1086,14 +1084,14 @@ inline QString QString::arg(short a, int fieldWidth, int base, QChar fillChar) c inline QString QString::arg(ushort a, int fieldWidth, int base, QChar fillChar) const { return arg(qulonglong(a), fieldWidth, base, fillChar); } -inline QString QString::section(QChar asep, int astart, int aend, SectionFlags aflags) const +inline QString QString::section(QChar asep, qsizetype astart, qsizetype aend, SectionFlags aflags) const { return section(QString(asep), astart, aend, aflags); } QT_WARNING_PUSH QT_WARNING_DISABLE_MSVC(4127) // "conditional expression is constant" QT_WARNING_DISABLE_INTEL(111) // "statement is unreachable" -inline int QString::toWCharArray(wchar_t *array) const +inline qsizetype QString::toWCharArray(wchar_t *array) const { return qToStringViewIgnoringNull(*this).toWCharArray(array); } @@ -1112,7 +1110,7 @@ int QStringView::toWCharArray(wchar_t *array) const QT_WARNING_POP -inline QString QString::fromWCharArray(const wchar_t *string, int size) +inline QString QString::fromWCharArray(const wchar_t *string, qsizetype size) { return sizeof(wchar_t) == sizeof(QChar) ? fromUtf16(reinterpret_cast<const char16_t *>(string), size) : fromUcs4(reinterpret_cast<const char32_t *>(string), size); @@ -1121,7 +1119,7 @@ inline QString QString::fromWCharArray(const wchar_t *string, int size) inline constexpr QString::QString() noexcept {} inline QString::~QString() {} -inline void QString::reserve(int asize) +inline void QString::reserve(qsizetype asize) { if (d->needsDetach() || asize >= capacity()) reallocData(uint(qMax(asize, size())) + 1u); @@ -1141,9 +1139,9 @@ inline void QString::squeeze() d->clearFlag(Data::CapacityReserved); } -inline QString &QString::setUtf16(const ushort *autf16, int asize) +inline QString &QString::setUtf16(const ushort *autf16, qsizetype asize) { return setUnicode(reinterpret_cast<const QChar *>(autf16), asize); } -inline QChar &QString::operator[](int i) +inline QChar &QString::operator[](qsizetype i) { Q_ASSERT(i >= 0 && i < size()); return data()[i]; } inline QChar &QString::front() { return operator[](0); } inline QChar &QString::back() { return operator[](size() - 1); } diff --git a/src/corelib/text/qstringmatcher.cpp b/src/corelib/text/qstringmatcher.cpp index e48d72f03e..449f475e66 100644 --- a/src/corelib/text/qstringmatcher.cpp +++ b/src/corelib/text/qstringmatcher.cpp @@ -288,7 +288,7 @@ void QStringMatcher::setCaseSensitivity(Qt::CaseSensitivity cs) \sa setPattern(), setCaseSensitivity() */ -int QStringMatcher::indexIn(const QString &str, int from) const +int QStringMatcher::indexIn(const QString &str, qsizetype from) const { return int(indexIn(QStringView(str), from)); } @@ -305,7 +305,7 @@ int QStringMatcher::indexIn(const QString &str, int from) const \sa setPattern(), setCaseSensitivity() */ -int QStringMatcher::indexIn(const QChar *str, int length, int from) const +int QStringMatcher::indexIn(const QChar *str, qsizetype length, qsizetype from) const { return int(indexIn(QStringView(str, length), from)); } diff --git a/src/corelib/text/qstringmatcher.h b/src/corelib/text/qstringmatcher.h index c731efcc97..104d4879b0 100644 --- a/src/corelib/text/qstringmatcher.h +++ b/src/corelib/text/qstringmatcher.h @@ -68,8 +68,8 @@ public: void setPattern(const QString &pattern); void setCaseSensitivity(Qt::CaseSensitivity cs); - int indexIn(const QString &str, int from = 0) const; - int indexIn(const QChar *str, int length, int from = 0) const; + int indexIn(const QString &str, qsizetype from = 0) const; + int indexIn(const QChar *str, qsizetype length, qsizetype from = 0) const; qsizetype indexIn(QStringView str, qsizetype from = 0) const; QString pattern() const; inline Qt::CaseSensitivity caseSensitivity() const { return q_cs; } diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp index 850def64ab..e1857e31ee 100644 --- a/tests/auto/corelib/text/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp @@ -333,7 +333,7 @@ class tst_QString : public QObject template <typename ArgType, typename MemFun> void insert_impl() const { do_apply1<ArgType, int>(MemFun(&QString::insert)); } template <typename ArgType> - void insert_impl() const { insert_impl<ArgType, QString &(QString::*)(int, const ArgType&)>(); } + void insert_impl() const { insert_impl<ArgType, QString &(QString::*)(qsizetype, const ArgType&)>(); } void insert_data(bool emptyIsNoop = false); class TransientDefaultLocale @@ -397,7 +397,7 @@ private slots: void prepend_qstringview_data() { prepend_data(true); } void prepend_qlatin1string() { prepend_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); } void prepend_qlatin1string_data() { prepend_data(true); } - void prepend_qcharstar_int() { prepend_impl<QPair<const QChar *, int>, QString &(QString::*)(const QChar *, int)>(); } + void prepend_qcharstar_int() { prepend_impl<QPair<const QChar *, int>, QString &(QString::*)(const QChar *, qsizetype)>(); } void prepend_qcharstar_int_data() { prepend_data(true); } void prepend_qchar() { prepend_impl<Reversed<QChar>, QString &(QString::*)(QChar)>(); } void prepend_qchar_data() { prepend_data(true); } @@ -416,7 +416,7 @@ private slots: void append_qstringview_data() { append_data(true); } void append_qlatin1string() { append_impl<QLatin1String, QString &(QString::*)(QLatin1String)>(); } void append_qlatin1string_data() { append_data(); } - void append_qcharstar_int() { append_impl<QPair<const QChar *, int>, QString&(QString::*)(const QChar *, int)>(); } + void append_qcharstar_int() { append_impl<QPair<const QChar *, int>, QString&(QString::*)(const QChar *, qsizetype)>(); } void append_qcharstar_int_data() { append_data(true); } void append_qchar() { append_impl<QChar, QString &(QString::*)(QChar)>(); } void append_qchar_data() { append_data(true); } @@ -453,19 +453,19 @@ private slots: void insert_qstring() { insert_impl<QString>(); } void insert_qstring_data() { insert_data(true); } - void insert_qstringview() { insert_impl<QStringView, QString &(QString::*)(int, QStringView)>(); } + void insert_qstringview() { insert_impl<QStringView, QString &(QString::*)(qsizetype, QStringView)>(); } void insert_qstringview_data() { insert_data(true); } - void insert_qlatin1string() { insert_impl<QLatin1String, QString &(QString::*)(int, QLatin1String)>(); } + void insert_qlatin1string() { insert_impl<QLatin1String, QString &(QString::*)(qsizetype, QLatin1String)>(); } void insert_qlatin1string_data() { insert_data(true); } - void insert_qcharstar_int() { insert_impl<QPair<const QChar *, int>, QString &(QString::*)(int, const QChar*, int) >(); } + void insert_qcharstar_int() { insert_impl<QPair<const QChar *, int>, QString &(QString::*)(qsizetype, const QChar*, qsizetype) >(); } void insert_qcharstar_int_data() { insert_data(true); } - void insert_qchar() { insert_impl<Reversed<QChar>, QString &(QString::*)(int, QChar)>(); } + void insert_qchar() { insert_impl<Reversed<QChar>, QString &(QString::*)(qsizetype, QChar)>(); } void insert_qchar_data() { insert_data(true); } void insert_qbytearray() { insert_impl<QByteArray>(); } void insert_qbytearray_data() { insert_data(true); } - void insert_char() { insert_impl<Reversed<char>, QString &(QString::*)(int, QChar)>(); } + void insert_char() { insert_impl<Reversed<char>, QString &(QString::*)(qsizetype, QChar)>(); } void insert_char_data() { insert_data(true); } - void insert_charstar() { insert_impl<const char *, QString &(QString::*)(int, const char*) >(); } + void insert_charstar() { insert_impl<const char *, QString &(QString::*)(qsizetype, const char*) >(); } void insert_charstar_data() { insert_data(true); } void insert_special_cases(); @@ -1213,7 +1213,7 @@ void tst_QString::chop_data() QTest::newRow("data0") << original << 1 << QString("abc"); QTest::newRow("data1") << original << 0 << original; QTest::newRow("data2") << original << -1 << original; - QTest::newRow("data3") << original << original.size() << QString(); + QTest::newRow("data3") << original << int(original.size()) << QString(); QTest::newRow("data4") << original << 1000 << QString(); } @@ -1581,27 +1581,27 @@ void tst_QString::lastIndexOf_data() QString a = "ABCDEFGHIEfGEFG"; - QTest::newRow("-1") << a << "G" << a.size() - 1 << 14 << true; + QTest::newRow("-1") << a << "G" << int(a.size()) - 1 << 14 << true; QTest::newRow("1") << a << "G" << - 1 << 14 << true; QTest::newRow("2") << a << "G" << -3 << 11 << true; QTest::newRow("3") << a << "G" << -5 << 6 << true; QTest::newRow("4") << a << "G" << 14 << 14 << true; QTest::newRow("5") << a << "G" << 13 << 11 << true; - QTest::newRow("6") << a << "B" << a.size() - 1 << 1 << true; + QTest::newRow("6") << a << "B" << int(a.size()) - 1 << 1 << true; QTest::newRow("7") << a << "B" << - 1 << 1 << true; QTest::newRow("8") << a << "B" << 1 << 1 << true; QTest::newRow("9") << a << "B" << 0 << -1 << true; - QTest::newRow("10") << a << "G" << -1 << a.size()-1 << true; - QTest::newRow("11") << a << "G" << a.size()-1 << a.size()-1 << true; - QTest::newRow("12") << a << "G" << a.size() << -1 << true; + QTest::newRow("10") << a << "G" << -1 << int(a.size())-1 << true; + QTest::newRow("11") << a << "G" << int(a.size())-1 << int(a.size())-1 << true; + QTest::newRow("12") << a << "G" << int(a.size()) << -1 << true; QTest::newRow("13") << a << "A" << 0 << 0 << true; - QTest::newRow("14") << a << "A" << -1*a.size() << 0 << true; + QTest::newRow("14") << a << "A" << -1*int(a.size()) << 0 << true; QTest::newRow("15") << a << "efg" << 0 << -1 << false; - QTest::newRow("16") << a << "efg" << a.size() << -1 << false; - QTest::newRow("17") << a << "efg" << -1 * a.size() << -1 << false; - QTest::newRow("19") << a << "efg" << a.size() - 1 << 12 << false; + QTest::newRow("16") << a << "efg" << int(a.size()) << -1 << false; + QTest::newRow("17") << a << "efg" << -1 * int(a.size()) << -1 << false; + QTest::newRow("19") << a << "efg" << int(a.size()) - 1 << 12 << false; QTest::newRow("20") << a << "efg" << 12 << 12 << false; QTest::newRow("21") << a << "efg" << -12 << -1 << false; QTest::newRow("22") << a << "efg" << 11 << 9 << false; @@ -1610,8 +1610,8 @@ void tst_QString::lastIndexOf_data() QTest::newRow("25") << "asd" << "asdf" << -1 << -1 << false; QTest::newRow("26") << "" << QString() << -1 << -1 << false; - QTest::newRow("27") << a << "" << a.size() << a.size() << false; - QTest::newRow("28") << a << "" << a.size() + 10 << -1 << false; + QTest::newRow("27") << a << "" << int(a.size()) << int(a.size()) << false; + QTest::newRow("28") << a << "" << int(a.size()) + 10 << -1 << false; } void tst_QString::lastIndexOf() diff --git a/tests/auto/corelib/text/qstringref/tst_qstringref.cpp b/tests/auto/corelib/text/qstringref/tst_qstringref.cpp index f6a2326af1..021e7f2967 100644 --- a/tests/auto/corelib/text/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/text/qstringref/tst_qstringref.cpp @@ -483,27 +483,27 @@ void tst_QStringRef::lastIndexOf_data() QString a = "ABCDEFGHIEfGEFG"; - QTest::newRow("-1") << a << "G" << a.size() - 1 << 14 << true; + QTest::newRow("-1") << a << "G" << int(a.size()) - 1 << 14 << true; QTest::newRow("1") << a << "G" << - 1 << 14 << true; QTest::newRow("2") << a << "G" << -3 << 11 << true; QTest::newRow("3") << a << "G" << -5 << 6 << true; QTest::newRow("4") << a << "G" << 14 << 14 << true; QTest::newRow("5") << a << "G" << 13 << 11 << true; - QTest::newRow("6") << a << "B" << a.size() - 1 << 1 << true; + QTest::newRow("6") << a << "B" << int(a.size()) - 1 << 1 << true; QTest::newRow("7") << a << "B" << - 1 << 1 << true; QTest::newRow("8") << a << "B" << 1 << 1 << true; QTest::newRow("9") << a << "B" << 0 << -1 << true; - QTest::newRow("10") << a << "G" << -1 << a.size()-1 << true; - QTest::newRow("11") << a << "G" << a.size()-1 << a.size()-1 << true; - QTest::newRow("12") << a << "G" << a.size() << -1 << true; + QTest::newRow("10") << a << "G" << -1 << int(a.size())-1 << true; + QTest::newRow("11") << a << "G" << int(a.size())-1 << int(a.size())-1 << true; + QTest::newRow("12") << a << "G" << int(a.size()) << -1 << true; QTest::newRow("13") << a << "A" << 0 << 0 << true; - QTest::newRow("14") << a << "A" << -1*a.size() << 0 << true; + QTest::newRow("14") << a << "A" << -1*int(a.size()) << 0 << true; QTest::newRow("15") << a << "efg" << 0 << -1 << false; - QTest::newRow("16") << a << "efg" << a.size() << -1 << false; - QTest::newRow("17") << a << "efg" << -1 * a.size() << -1 << false; - QTest::newRow("19") << a << "efg" << a.size() - 1 << 12 << false; + QTest::newRow("16") << a << "efg" << int(a.size()) << -1 << false; + QTest::newRow("17") << a << "efg" << -1 * int(a.size()) << -1 << false; + QTest::newRow("19") << a << "efg" << int(a.size()) - 1 << 12 << false; QTest::newRow("20") << a << "efg" << 12 << 12 << false; QTest::newRow("21") << a << "efg" << -12 << -1 << false; QTest::newRow("22") << a << "efg" << 11 << 9 << false; @@ -512,8 +512,8 @@ void tst_QStringRef::lastIndexOf_data() QTest::newRow("25") << "asd" << "asdf" << -1 << -1 << false; QTest::newRow("26") << "" << QString() << -1 << -1 << false; - QTest::newRow("27") << a << "" << a.size() << a.size() << false; - QTest::newRow("28") << a << "" << a.size() + 10 << -1 << false; + QTest::newRow("27") << a << "" << int(a.size()) << int(a.size()) << false; + QTest::newRow("28") << a << "" << int(a.size()) + 10 << -1 << false; } void tst_QStringRef::lastIndexOf() diff --git a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp index 3da32a2842..4defd0da27 100644 --- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp +++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp @@ -1557,26 +1557,26 @@ void tst_QTextCursor::update_data() QTest::newRow("removeInsideSelection") << text << /*position*/ 0 - << /*anchor*/ text.length() + << /*anchor*/ int(text.length()) // delete 'big' << 6 << 6 + charsToDelete << QString() // don't insert anything, just remove << /*expectedPosition*/ 0 - << /*expectedAnchor*/ text.length() - charsToDelete + << /*expectedAnchor*/ int(text.length() - charsToDelete) ; text = "Hello big world"; charsToDelete = 3; QTest::newRow("removeInsideSelectionWithSwappedAnchorAndPosition") << text - << /*position*/ text.length() + << /*position*/ int(text.length()) << /*anchor*/ 0 // delete 'big' << 6 << 6 + charsToDelete << QString() // don't insert anything, just remove - << /*expectedPosition*/ text.length() - charsToDelete + << /*expectedPosition*/ int(text.length() - charsToDelete) << /*expectedAnchor*/ 0 ; @@ -1587,13 +1587,13 @@ void tst_QTextCursor::update_data() QTest::newRow("replaceInsideSelection") << text << /*position*/ 0 - << /*anchor*/ text.length() + << /*anchor*/ int(text.length()) // delete 'big' ... << 6 << 6 + charsToDelete << textToInsert // ... and replace 'big' with 'small' << /*expectedPosition*/ 0 - << /*expectedAnchor*/ text.length() - charsToDelete + textToInsert.length() + << /*expectedAnchor*/ int(text.length() - charsToDelete + textToInsert.length()) ; text = "Hello big world"; @@ -1601,13 +1601,13 @@ void tst_QTextCursor::update_data() textToInsert = "small"; QTest::newRow("replaceInsideSelectionWithSwappedAnchorAndPosition") << text - << /*position*/ text.length() + << /*position*/ int(text.length()) << /*anchor*/ 0 // delete 'big' ... << 6 << 6 + charsToDelete << textToInsert // ... and replace 'big' with 'small' - << /*expectedPosition*/ text.length() - charsToDelete + textToInsert.length() + << /*expectedPosition*/ int(text.length() - charsToDelete + textToInsert.length()) << /*expectedAnchor*/ 0 ; @@ -1616,14 +1616,14 @@ void tst_QTextCursor::update_data() charsToDelete = 3; QTest::newRow("removeBeforeSelection") << text - << /*position*/ text.length() - 5 - << /*anchor*/ text.length() + << /*position*/ int(text.length() - 5) + << /*anchor*/ int(text.length()) // delete 'big' << 6 << 6 + charsToDelete << QString() // don't insert anything, just remove - << /*expectedPosition*/ text.length() - 5 - charsToDelete - << /*expectedAnchor*/ text.length() - charsToDelete + << /*expectedPosition*/ int(text.length() - 5 - charsToDelete) + << /*expectedAnchor*/ int(text.length() - charsToDelete) ; text = "Hello big world"; |