From fc2ed2361c32f6ab3f89adeb414fa8929f667476 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 23 Jul 2019 16:31:56 +0200 Subject: Tidy up some messy code in QLocale It was using if/else with extraneous braces, where simple ternary operators will do. It was doing a StringView content check clumsily when mid() and startsWith() suffice. Change-Id: I693f29ce5b425d53469d2c756fe27459f36470e9 Reviewed-by: Marc Mutz --- src/corelib/text/qlocale.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src/corelib/text/qlocale.cpp') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index 270eac8610..5685d87c85 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -567,8 +567,8 @@ QString qt_readEscapedFormatString(QStringView format, int *idx) while (i < format.size()) { if (format.at(i).unicode() == '\'') { - if (i + 1 < format.size() && format.at(i + 1).unicode() == '\'') { - // "''" inside of a quoted string + if (format.mid(i + 1).startsWith(QLatin1Char('\''))) { + // "''" inside a quoted string result.append(QLatin1Char('\'')); i += 2; } else { @@ -3186,31 +3186,19 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da case 'a': used = true; - if (i + 1 < format.size() && format.at(i + 1).unicode() == 'p') { - repeat = 2; - } else { - repeat = 1; - } + repeat = format.mid(i + 1).startsWith(QLatin1Char('p')) ? 2 : 1; result.append(time.hour() < 12 ? q->amText().toLower() : q->pmText().toLower()); break; case 'A': used = true; - if (i + 1 < format.size() && format.at(i + 1).unicode() == 'P') { - repeat = 2; - } else { - repeat = 1; - } + repeat = format.mid(i + 1).startsWith(QLatin1Char('P')) ? 2 : 1; result.append(time.hour() < 12 ? q->amText().toUpper() : q->pmText().toUpper()); break; case 'z': used = true; - if (repeat >= 3) { - repeat = 3; - } else { - repeat = 1; - } + repeat = (repeat >= 3) ? 3 : 1; // note: the millisecond component is treated like the decimal part of the seconds // so ms == 2 is always printed as "002", but ms == 200 can be either "2" or "200" @@ -3229,20 +3217,16 @@ QString QLocalePrivate::dateTimeToString(QStringView format, const QDateTime &da used = true; repeat = 1; // If we have a QDateTime use the time spec otherwise use the current system tzname - if (formatDate) { - result.append(datetime.timeZoneAbbreviation()); - } else { - result.append(QDateTime::currentDateTime().timeZoneAbbreviation()); - } + result.append(formatDate ? datetime.timeZoneAbbreviation() + : QDateTime::currentDateTime().timeZoneAbbreviation()); break; default: break; } } - if (!used) { + if (!used) result.append(QString(repeat, c)); - } i += repeat; } -- cgit v1.2.3