diff options
author | Liang Qi <liang.qi@qt.io> | 2016-05-12 07:31:50 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-05-12 08:33:08 +0200 |
commit | 990969655c5fb4d03682e96df9b12101f5ee9815 (patch) | |
tree | b8fb5c50285105c8bc5a938fb50f93ff9f24889d /src/corelib/tools/qdatetimeparser.cpp | |
parent | a213011a53f12f101d08a04afc8fdacd2d54a232 (diff) | |
parent | e64b2234e829cc47872225debcf80d6c06db18f0 (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
config_help.txt
configure
src/corelib/io/qprocess_wince.cpp
src/plugins/platforms/windows/qwindowstheme.cpp
src/plugins/platforms/xcb/qxcbbackingstore.cpp
tests/auto/corelib/tools/qtimezone/BLACKLIST
tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
Change-Id: I26644d1cb3b78412c8ff285e2a55bea1bd641c01
Diffstat (limited to 'src/corelib/tools/qdatetimeparser.cpp')
-rw-r--r-- | src/corelib/tools/qdatetimeparser.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index c1abdf11a7..8ddf1d9e41 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -313,7 +313,7 @@ int QDateTimeParser::sectionPos(const SectionNode &sn) const */ -static QString unquote(const QString &str) +static QString unquote(const QStringRef &str) { const QChar quote(QLatin1Char('\'')); const QChar slash(QLatin1Char('\\')); @@ -357,10 +357,8 @@ static inline int countRepeat(const QString &str, int index, int maxCount) static inline void appendSeparator(QStringList *list, const QString &string, int from, int size, int lastQuote) { - QString str(string.mid(from, size)); - if (lastQuote >= from) - str = unquote(str); - list->append(str); + const QStringRef separator = string.midRef(from, size); + list->append(lastQuote >= from ? unquote(separator) : separator.toString()); } @@ -471,7 +469,7 @@ bool QDateTimeParser::parseFormat(const QString &newFormat) if (parserType != QVariant::Time) { const SectionNode sn = { MonthSection, i - add, countRepeat(newFormat, i, 4), 0 }; newSectionNodes.append(sn); - newSeparators.append(unquote(newFormat.mid(index, i - index))); + newSeparators.append(unquote(newFormat.midRef(index, i - index))); i += sn.count - 1; index = i + 1; newDisplay |= MonthSection; @@ -553,19 +551,20 @@ int QDateTimeParser::sectionSize(int sectionIndex) const // is the previous value and displayText() is the new value. // The size difference is always due to leading zeroes. int sizeAdjustment = 0; - if (displayText().size() != text.size()) { + const int displayTextSize = displayText().size(); + if (displayTextSize != text.size()) { // Any zeroes added before this section will affect our size. int preceedingZeroesAdded = 0; if (sectionNodes.size() > 1 && context == DateTimeEdit) { - for (QVector<SectionNode>::ConstIterator sectionIt = sectionNodes.constBegin(); - sectionIt != sectionNodes.constBegin() + sectionIndex; ++sectionIt) { + const auto begin = sectionNodes.cbegin(); + const auto end = begin + sectionIndex; + for (auto sectionIt = begin; sectionIt != end; ++sectionIt) preceedingZeroesAdded += sectionIt->zeroesAdded; - } } sizeAdjustment = preceedingZeroesAdded; } - return displayText().size() + sizeAdjustment - sectionPos(sectionIndex) - separators.last().size(); + return displayTextSize + sizeAdjustment - sectionPos(sectionIndex) - separators.last().size(); } else { return sectionPos(sectionIndex + 1) - sectionPos(sectionIndex) - separators.at(sectionIndex + 1).size(); @@ -847,7 +846,7 @@ int QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionInde if (skipToNextSection(sectionIndex, currentValue, digitsStr)) { state = Acceptable; const int missingZeroes = sectionmaxsize - digitsStr.size(); - text.insert(index, QString().fill(QLatin1Char('0'), missingZeroes)); + text.insert(index, QString(missingZeroes, QLatin1Char('0'))); used = sectionmaxsize; cursorPosition += missingZeroes; ++(const_cast<QDateTimeParser*>(this)->sectionNodes[sectionIndex].zeroesAdded); @@ -1164,11 +1163,12 @@ end: if (newCurrentValue.daysTo(minimum) != 0) { break; } - toMin = newCurrentValue.time().msecsTo(minimum.time()); + const QTime time = newCurrentValue.time(); + toMin = time.msecsTo(minimum.time()); if (newCurrentValue.daysTo(maximum) > 0) { toMax = -1; // can't get to max } else { - toMax = newCurrentValue.time().msecsTo(maximum.time()); + toMax = time.msecsTo(maximum.time()); } } else { toMin = newCurrentValue.daysTo(minimum); @@ -1555,10 +1555,7 @@ QString QDateTimeParser::SectionNode::format() const qWarning("QDateTimeParser::sectionFormat Internal error 2"); return QString(); } - - QString str; - str.fill(fillChar, count); - return str; + return QString(count, fillChar); } |