replaceArgEscapes(): use qsizetype in place of int ant uint

The uint, particularly, was requiring some contortions to avoid
getting a "negative" value, where using qsizetype makes it harmless,
as the resulting loops are then no-ops. In the process, document the
slightly eccentric semantics of one of the retyped variables.

Change-Id: Idaad4cfde9ed9d24e1bcbf03c2bdb10b62e07916
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Edward Welbourne 2021-08-02 17:34:44 +02:00
parent 47ead6ce2c
commit 0dca7afaee

View File

@ -7763,13 +7763,14 @@ static ArgEscapeData findArgEscapes(QStringView s)
return d;
}
static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, int field_width,
static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, qsizetype field_width,
QStringView arg, QStringView larg, QChar fillChar)
{
const QChar *uc_begin = s.begin();
const QChar *uc_end = s.end();
int abs_field_width = qAbs(field_width);
// Negative field-width for right-padding, positive for left-padding:
const qsizetype abs_field_width = qAbs(field_width);
qsizetype result_len = s.length()
- d.escape_len
+ (d.occurrences - d.locale_occurrences)
@ -7818,10 +7819,11 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, int fiel
rc += escape_start - text_start;
const QStringView use = localize ? larg : arg;
const uint pad_chars = qMax(abs_field_width, use.length()) - use.length();
const qsizetype pad_chars = abs_field_width - use.length();
// (If negative, relevant loops are no-ops: no need to check.)
if (field_width > 0) { // left padded
for (uint i = 0; i < pad_chars; ++i)
for (qsizetype i = 0; i < pad_chars; ++i)
*rc++ = fillChar;
}
@ -7829,7 +7831,7 @@ static QString replaceArgEscapes(QStringView s, const ArgEscapeData &d, int fiel
rc += use.length();
if (field_width < 0) { // right padded
for (uint i = 0; i < pad_chars; ++i)
for (qsizetype i = 0; i < pad_chars; ++i)
*rc++ = fillChar;
}