From a974968d615ecbf3de6fe8031881d1ce07dd5a47 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 20 Jul 2022 19:21:06 +0200 Subject: [PATCH] Fix QString::toHtmlEscaped() for >2Gi character strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More unfinished int → qsizetype porting. Fixes: QTBUG-105104 Change-Id: I3470de31c476b3d7736661550916828e43546573 Reviewed-by: Thiago Macieira Reviewed-by: Edward Welbourne (cherry picked from commit c1991c63fc081a42ed3e6a28f82f395c54ef42a1) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qstring.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index 1a78c1d0cd8..2507802b6ba 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -10896,19 +10896,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) == u'<') + for (QChar ch : *this) { + if (ch == u'<') rich += "<"_L1; - else if (at(i) == u'>') + else if (ch == u'>') rich += ">"_L1; - else if (at(i) == u'&') + else if (ch == u'&') rich += "&"_L1; - else if (at(i) == u'"') + else if (ch == u'"') rich += """_L1; else - rich += at(i); + rich += ch; } rich.squeeze(); return rich;