summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-01-02 15:13:37 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-01-24 19:54:58 +0200
commit3027e498938bc7bfb51d601ab308827b48c16622 (patch)
tree76e20dd8b5a35523d0b13794e742095cf403184b
parentb49e2bb0849ed423e68398d5a10a3cc079bff589 (diff)
QDateTimeParser: don't shadow member variable
Rename local var to lastVal, this is less confusing and less error prone. Seeing "last" in the code one would have to ask which one it is, the member var, a parameter or a local var? and it could be missed especially when reading code quickly, which happens especially if it's not what you're focusing on now, i.e. you're fixing something else and want to check this code quickly. Change-Id: Id1742fd5f47ce65faf4d95f408ab3eb1f16e8c45 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/corelib/time/qdatetimeparser.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp
index 068566cc9ac..c4e4ddbef77 100644
--- a/src/corelib/time/qdatetimeparser.cpp
+++ b/src/corelib/time/qdatetimeparser.cpp
@@ -863,7 +863,7 @@ QDateTimeParser::parseSection(const QDateTime &currentValue, int sectionIndex, i
const int absMax = absoluteMax(sectionIndex);
const int absMin = absoluteMin(sectionIndex);
- int last = -1;
+ int lastVal = -1;
for (; digitsStr.size(); digitsStr.chop(1)) {
bool ok = false;
@@ -879,52 +879,52 @@ QDateTimeParser::parseSection(const QDateTime &currentValue, int sectionIndex, i
}
QDTPDEBUG << digitsStr << value << digitsStr.size();
- last = value;
+ lastVal = value;
used += digitsStr.size();
break;
}
- if (last == -1) {
+ if (lastVal == -1) {
const auto &sep = separators.at(sectionIndex + 1);
if (sep.startsWith(sectionTextRef[0])
|| (negate && sep.startsWith(m_text.at(offset))))
result = ParsedSection(Intermediate, 0, 0);
else
QDTPDEBUG << "invalid because" << sectionTextRef << "can't become a uint"
- << last;
+ << lastVal;
} else {
if (negate)
- last = -last;
+ lastVal = -lastVal;
const FieldInfo fi = fieldInfo(sectionIndex);
const bool unfilled = used - negativeYearOffset < sectionmaxsize;
if (unfilled && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002
for (int i = used; i < sectionmaxsize; ++i)
- last *= 10;
+ lastVal *= 10;
}
// Even those *= 10s can't take last above absMax:
- Q_ASSERT(negate ? last >= absMin : last <= absMax);
- if (negate ? last > absMax : last < absMin) {
+ Q_ASSERT(negate ? lastVal >= absMin : lastVal <= absMax);
+ if (negate ? lastVal > absMax : lastVal < absMin) {
if (unfilled) {
- result = ParsedSection(Intermediate, last, used);
+ result = ParsedSection(Intermediate, lastVal, used);
} else if (negate) {
- QDTPDEBUG << "invalid because" << last << "is greater than absoluteMax"
+ QDTPDEBUG << "invalid because" << lastVal << "is greater than absoluteMax"
<< absMax;
} else {
- QDTPDEBUG << "invalid because" << last << "is less than absoluteMin"
+ QDTPDEBUG << "invalid because" << lastVal << "is less than absoluteMin"
<< absMin;
}
} else if (unfilled && (fi & (FixedWidth | Numeric)) == (FixedWidth | Numeric)) {
if (skipToNextSection(sectionIndex, defaultValue, digitsStr)) {
const int missingZeroes = sectionmaxsize - digitsStr.size();
- result = ParsedSection(Acceptable, last, sectionmaxsize, missingZeroes);
+ result = ParsedSection(Acceptable, lastVal, sectionmaxsize, missingZeroes);
m_text.insert(offset, QString(missingZeroes, u'0'));
++(const_cast<QDateTimeParser*>(this)->sectionNodes[sectionIndex].zeroesAdded);
} else {
- result = ParsedSection(Intermediate, last, used);;
+ result = ParsedSection(Intermediate, lastVal, used);;
}
} else {
- result = ParsedSection(Acceptable, last, used);
+ result = ParsedSection(Acceptable, lastVal, used);
}
}
}