qtextdocument: use qsizetype more
in Qt::mightBeRichText, Qt::convertFromPlainText and emitFrameStyle to support large strings Change-Id: I7187bd81d3cbcc11ba898e015bd2a8ec64e3bf34 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 33d606412d8c2dc9ad3c0129af5bc8a74ce650be) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit f4cd637c8a13310e5952c30677ce144ec3d22633) (cherry picked from commit cf5519e983123b787990b688f7c702744c8837c7) Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
14e7f0c473
commit
4fd124b432
@ -99,7 +99,7 @@ bool Qt::mightBeRichText(const QString& text)
|
|||||||
{
|
{
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
int start = 0;
|
qsizetype start = 0;
|
||||||
|
|
||||||
while (start < text.length() && text.at(start).isSpace())
|
while (start < text.length() && text.at(start).isSpace())
|
||||||
++start;
|
++start;
|
||||||
@ -122,7 +122,7 @@ bool Qt::mightBeRichText(const QString& text)
|
|||||||
|
|
||||||
if (QStringView{text}.mid(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0)
|
if (QStringView{text}.mid(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0)
|
||||||
return true;
|
return true;
|
||||||
int open = start;
|
qsizetype open = start;
|
||||||
while (open < text.length() && text.at(open) != QLatin1Char('<')
|
while (open < text.length() && text.at(open) != QLatin1Char('<')
|
||||||
&& text.at(open) != QLatin1Char('\n')) {
|
&& text.at(open) != QLatin1Char('\n')) {
|
||||||
if (text.at(open) == QLatin1Char('&') && QStringView{text}.mid(open + 1, 3) == QLatin1String("lt;"))
|
if (text.at(open) == QLatin1Char('&') && QStringView{text}.mid(open + 1, 3) == QLatin1String("lt;"))
|
||||||
@ -130,10 +130,10 @@ bool Qt::mightBeRichText(const QString& text)
|
|||||||
++open;
|
++open;
|
||||||
}
|
}
|
||||||
if (open < text.length() && text.at(open) == QLatin1Char('<')) {
|
if (open < text.length() && text.at(open) == QLatin1Char('<')) {
|
||||||
const int close = text.indexOf(QLatin1Char('>'), open);
|
const qsizetype close = text.indexOf(QLatin1Char('>'), open);
|
||||||
if (close > -1) {
|
if (close > -1) {
|
||||||
QString tag;
|
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())
|
if (text[i].isDigit() || text[i].isLetter())
|
||||||
tag += text[i];
|
tag += text[i];
|
||||||
else if (!tag.isEmpty() && text[i].isSpace())
|
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)
|
QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode)
|
||||||
{
|
{
|
||||||
int col = 0;
|
qsizetype col = 0;
|
||||||
QString rich;
|
QString rich;
|
||||||
rich += QLatin1String("<p>");
|
rich += QLatin1String("<p>");
|
||||||
for (int i = 0; i < plain.length(); ++i) {
|
for (qsizetype i = 0; i < plain.length(); ++i) {
|
||||||
if (plain[i] == QLatin1Char('\n')){
|
if (plain[i] == QLatin1Char('\n')){
|
||||||
int c = 1;
|
qsizetype c = 1;
|
||||||
while (i+1 < plain.length() && plain[i+1] == QLatin1Char('\n')) {
|
while (i+1 < plain.length() && plain[i+1] == QLatin1Char('\n')) {
|
||||||
i++;
|
i++;
|
||||||
c++;
|
c++;
|
||||||
@ -3402,7 +3402,7 @@ void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType
|
|||||||
{
|
{
|
||||||
QLatin1String styleAttribute(" style=\"");
|
QLatin1String styleAttribute(" style=\"");
|
||||||
html += styleAttribute;
|
html += styleAttribute;
|
||||||
const int originalHtmlLength = html.length();
|
const qsizetype originalHtmlLength = html.length();
|
||||||
|
|
||||||
if (frameType == TextFrame)
|
if (frameType == TextFrame)
|
||||||
html += QLatin1String("-qt-table-type: frame;");
|
html += QLatin1String("-qt-table-type: frame;");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user