From 4fd124b432f49c359353c3cc0db16dffb738d0fb Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Wed, 4 Oct 2023 14:40:40 +0300 Subject: [PATCH] qtextdocument: use qsizetype more MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in Qt::mightBeRichText, Qt::convertFromPlainText and emitFrameStyle to support large strings Change-Id: I7187bd81d3cbcc11ba898e015bd2a8ec64e3bf34 Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 33d606412d8c2dc9ad3c0129af5bc8a74ce650be) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit f4cd637c8a13310e5952c30677ce144ec3d22633) (cherry picked from commit cf5519e983123b787990b688f7c702744c8837c7) Reviewed-by: Edward Welbourne --- src/gui/text/qtextdocument.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 5631185b3aa..a2802b796b3 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -99,7 +99,7 @@ bool Qt::mightBeRichText(const QString& text) { if (text.isEmpty()) return false; - int start = 0; + qsizetype start = 0; while (start < text.length() && text.at(start).isSpace()) ++start; @@ -122,7 +122,7 @@ bool Qt::mightBeRichText(const QString& text) if (QStringView{text}.mid(start, 5).compare(QLatin1String("'), open); + const qsizetype close = text.indexOf(QLatin1Char('>'), open); if (close > -1) { QString tag; - for (int i = open+1; i < close; ++i) { + for (qsizetype i = open+1; i < close; ++i) { if (text[i].isDigit() || text[i].isLetter()) tag += text[i]; else if (!tag.isEmpty() && text[i].isSpace()) @@ -165,12 +165,12 @@ bool Qt::mightBeRichText(const QString& text) */ QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) { - int col = 0; + qsizetype col = 0; QString rich; rich += QLatin1String("

"); - for (int i = 0; i < plain.length(); ++i) { + for (qsizetype i = 0; i < plain.length(); ++i) { if (plain[i] == QLatin1Char('\n')){ - int c = 1; + qsizetype c = 1; while (i+1 < plain.length() && plain[i+1] == QLatin1Char('\n')) { i++; c++; @@ -3402,7 +3402,7 @@ void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType { QLatin1String styleAttribute(" style=\""); html += styleAttribute; - const int originalHtmlLength = html.length(); + const qsizetype originalHtmlLength = html.length(); if (frameType == TextFrame) html += QLatin1String("-qt-table-type: frame;");