Port QString to qsizetype

Change-Id: Id9477ccfabadd578546bb265a9483f128efb6736
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Lars Knoll 2020-06-25 12:37:10 +02:00
parent df853fed66
commit 9a9a1a2a2e
9 changed files with 360 additions and 375 deletions

View File

@ -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);

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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); }

View File

@ -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));
}

View File

@ -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; }

View File

@ -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()

View File

@ -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()

View File

@ -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";