Minor tidies in example's XML converter

Make a local variable more local, set a variable only once its new
value is known to be valid.

Task-number: QTBUG-111228
Change-Id: Ib6aa16e8c834f89c6ccc0715f20b0e5f0a7f3b6d
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
(cherry picked from commit 40b07ee887d9717088e3189b15c86a5c87759b1d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2023-09-04 18:49:12 +02:00 committed by Qt Cherry-pick Bot
parent 19242733aa
commit 4b39596512

View File

@ -180,23 +180,23 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
text = text.trimmed(); text = text.trimmed();
QVariant result; QVariant result;
bool ok;
if (type.isEmpty()) { if (type.isEmpty()) {
// ok // ok
} else if (type == QLatin1String("number")) { } else if (type == QLatin1String("number")) {
// try integer first // try integer first
bool ok;
qint64 v = text.toLongLong(&ok); qint64 v = text.toLongLong(&ok);
if (ok) { if (ok) {
result = v; result = v;
} else { } else {
// let's see floating point // let's see floating point
double d = text.toDouble(&ok); double d = text.toDouble(&ok);
result = d;
if (!ok) { if (!ok) {
fprintf(stderr, "%lld:%lld: Invalid XML: could not interpret '%s' as a number.\n", fprintf(stderr, "%lld:%lld: Invalid XML: could not interpret '%s' as a number.\n",
xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString())); xml.lineNumber(), xml.columnNumber(), qPrintable(text.toString()));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
result = d;
} }
} else if (type == QLatin1String("bytes")) { } else if (type == QLatin1String("bytes")) {
QByteArray data = text.toLatin1(); QByteArray data = text.toLatin1();