diff options
Diffstat (limited to 'src/corelib/text/qstring.cpp')
-rw-r--r-- | src/corelib/text/qstring.cpp | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 58426442ec..6ec93835b4 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -647,6 +647,8 @@ Q_CORE_EXPORT void qt_from_latin1(char16_t *dst, const char *str, size_t size) n # endif #endif #if defined(__mips_dsp) + static_assert(sizeof(qsizetype) == sizeof(int), + "oops, the assembler implementation needs to be called in a loop"); if (size > 20) qt_fromlatin1_mips_asm_unroll8(dst, str, size); else @@ -781,10 +783,10 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len // 1) neon has unsigned comparison // 2) packing is done to 64 bits (8 x 8bits component). if (length >= 16) { - const int chunkCount = length >> 3; // divided by 8 + const qsizetype chunkCount = length >> 3; // divided by 8 const uint16x8_t questionMark = vdupq_n_u16('?'); // set const uint16x8_t thresholdMask = vdupq_n_u16(0xff); // set - for (int i = 0; i < chunkCount; ++i) { + for (qsizetype i = 0; i < chunkCount; ++i) { uint16x8_t chunk = vld1q_u16((uint16_t *)src); // load src += 8; @@ -802,6 +804,8 @@ static void qt_to_latin1_internal(uchar *dst, const char16_t *src, qsizetype len } #endif #if defined(__mips_dsp) + static_assert(sizeof(qsizetype) == sizeof(int), + "oops, the assembler implementation needs to be called in a loop"); qt_toLatin1_mips_dsp_asm(dst, src, length); #else while (length--) { @@ -3930,7 +3934,6 @@ QString &QString::replace(QChar c, QLatin1String after, Qt::CaseSensitivity cs) go through QObject::tr(), for example. */ -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns the index position of the first occurrence of the string \a str in this string, searching forward from index position \a @@ -3952,7 +3955,6 @@ qsizetype QString::indexOf(const QString &str, qsizetype from, Qt::CaseSensitivi { return QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs); } -#endif // QT_STRINGVIEW_LEVEL < 2 /*! \fn qsizetype QString::indexOf(QStringView str, qsizetype from, Qt::CaseSensitivity cs) const @@ -4008,7 +4010,6 @@ qsizetype QString::indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) con return qFindChar(QStringView(unicode(), length()), ch, from, cs); } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns the index position of the last occurrence of the string \a str in this string, searching backward from index position \a @@ -4055,7 +4056,6 @@ qsizetype QString::lastIndexOf(const QString &str, qsizetype from, Qt::CaseSensi \sa indexOf(), contains(), count() */ -#endif // QT_STRINGVIEW_LEVEL < 2 /*! \since 4.5 @@ -4341,7 +4341,6 @@ qsizetype QString::count(QStringView str, Qt::CaseSensitivity cs) const return QtPrivate::count(*this, str, cs); } -#if QT_STRINGVIEW_LEVEL < 2 /*! \fn bool QString::contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const Returns \c true if this string contains an occurrence of the string @@ -4355,7 +4354,6 @@ qsizetype QString::count(QStringView str, Qt::CaseSensitivity cs) const \sa indexOf(), count() */ -#endif // QT_STRINGVIEW_LEVEL < 2 /*! \fn bool QString::contains(QLatin1String str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const \since 5.3 @@ -4935,7 +4933,6 @@ QString QString::mid(qsizetype position, qsizetype n) const \sa endsWith(), first(), last(), sliced(), chop(), truncate() */ -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns \c true if the string starts with \a s; otherwise returns \c false. @@ -4951,7 +4948,6 @@ bool QString::startsWith(const QString& s, Qt::CaseSensitivity cs) const { return qt_starts_with(*this, s, cs); } -#endif /*! \overload startsWith() @@ -4986,7 +4982,6 @@ bool QString::startsWith(QChar c, Qt::CaseSensitivity cs) const \sa endsWith() */ -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns \c true if the string ends with \a s; otherwise returns \c false. @@ -5002,7 +4997,6 @@ bool QString::endsWith(const QString &s, Qt::CaseSensitivity cs) const { return qt_ends_with(*this, s, cs); } -#endif // QT_STRINGVIEW_LEVEL < 2 /*! \fn bool QString::endsWith(QStringView str, Qt::CaseSensitivity cs) const @@ -5486,7 +5480,7 @@ QString QString::fromUtf8(QByteArrayView ba) host byte order is assumed. This function is slow compared to the other Unicode conversions. - Use QString(const QChar *, int) or QString(const QChar *) if possible. + Use QString(const QChar *, qsizetype) or QString(const QChar *) if possible. QString makes a deep copy of the Unicode data. @@ -6085,7 +6079,6 @@ QString& QString::fill(QChar ch, qsizetype size) sensitivity setting \a cs. */ -#if QT_STRINGVIEW_LEVEL < 2 /*! \overload compare() \since 4.2 @@ -6101,7 +6094,6 @@ int QString::compare(const QString &other, Qt::CaseSensitivity cs) const noexcep { return QtPrivate::compareStrings(*this, other, cs); } -#endif /*! \internal @@ -6626,9 +6618,9 @@ QString QString::asprintf(const char *cformat, ...) return s; } -static void append_utf8(QString &qs, const char *cs, int len) +static void append_utf8(QString &qs, const char *cs, qsizetype len) { - const int oldSize = qs.size(); + const qsizetype oldSize = qs.size(); qs.resize(oldSize + len); const QChar *newEnd = QUtf8::convertToUnicode(qs.data() + oldSize, QByteArrayView(cs, len)); qs.resize(newEnd - qs.constData()); @@ -7946,7 +7938,6 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, int fiel return result; } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns a copy of this string with the lowest numbered place marker replaced by string \a a, i.e., \c %1, \c %2, ..., \c %99. @@ -7980,7 +7971,6 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const { return arg(qToStringViewIgnoringNull(a), fieldWidth, fillChar); } -#endif // QT_STRINGVIEW_LEVEL < 2 /*! \overload @@ -8360,7 +8350,7 @@ static inline char16_t to_unicode(const char c) { return QLatin1Char{c}.unicode( template <typename Char> static int getEscape(const Char *uc, qsizetype *pos, qsizetype len, int maxNumber = 999) { - int i = *pos; + qsizetype i = *pos; ++i; if (i < len && uc[i] == QLatin1Char('L')) ++i; @@ -10585,19 +10575,19 @@ qsizetype QtPrivate::count(QStringView haystack, const QRegularExpression &re) QString QString::toHtmlEscaped() const { QString rich; - const int len = length(); + const qsizetype len = length(); rich.reserve(qsizetype(len * 1.1)); - for (int i = 0; i < len; ++i) { - if (at(i) == QLatin1Char('<')) + for (QChar ch : *this) { + if (ch == u'<') rich += QLatin1String("<"); - else if (at(i) == QLatin1Char('>')) + else if (ch == u'>') rich += QLatin1String(">"); - else if (at(i) == QLatin1Char('&')) + else if (ch == u'&') rich += QLatin1String("&"); - else if (at(i) == QLatin1Char('"')) + else if (ch == u'"') rich += QLatin1String("""); else - rich += at(i); + rich += ch; } rich.squeeze(); return rich; |