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>
This commit is contained in:
parent
b49e2bb084
commit
3027e49893
@ -863,7 +863,7 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, i
|
|||||||
const int absMax = absoluteMax(sectionIndex);
|
const int absMax = absoluteMax(sectionIndex);
|
||||||
const int absMin = absoluteMin(sectionIndex);
|
const int absMin = absoluteMin(sectionIndex);
|
||||||
|
|
||||||
int last = -1;
|
int lastVal = -1;
|
||||||
|
|
||||||
for (; digitsStr.size(); digitsStr.chop(1)) {
|
for (; digitsStr.size(); digitsStr.chop(1)) {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
@ -879,52 +879,52 @@ QDateTimeParser::parseSection(const QDateTime ¤tValue, int sectionIndex, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
QDTPDEBUG << digitsStr << value << digitsStr.size();
|
QDTPDEBUG << digitsStr << value << digitsStr.size();
|
||||||
last = value;
|
lastVal = value;
|
||||||
used += digitsStr.size();
|
used += digitsStr.size();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last == -1) {
|
if (lastVal == -1) {
|
||||||
const auto &sep = separators.at(sectionIndex + 1);
|
const auto &sep = separators.at(sectionIndex + 1);
|
||||||
if (sep.startsWith(sectionTextRef[0])
|
if (sep.startsWith(sectionTextRef[0])
|
||||||
|| (negate && sep.startsWith(m_text.at(offset))))
|
|| (negate && sep.startsWith(m_text.at(offset))))
|
||||||
result = ParsedSection(Intermediate, 0, 0);
|
result = ParsedSection(Intermediate, 0, 0);
|
||||||
else
|
else
|
||||||
QDTPDEBUG << "invalid because" << sectionTextRef << "can't become a uint"
|
QDTPDEBUG << "invalid because" << sectionTextRef << "can't become a uint"
|
||||||
<< last;
|
<< lastVal;
|
||||||
} else {
|
} else {
|
||||||
if (negate)
|
if (negate)
|
||||||
last = -last;
|
lastVal = -lastVal;
|
||||||
const FieldInfo fi = fieldInfo(sectionIndex);
|
const FieldInfo fi = fieldInfo(sectionIndex);
|
||||||
const bool unfilled = used - negativeYearOffset < sectionmaxsize;
|
const bool unfilled = used - negativeYearOffset < sectionmaxsize;
|
||||||
if (unfilled && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002
|
if (unfilled && fi & Fraction) { // typing 2 in a zzz field should be .200, not .002
|
||||||
for (int i = used; i < sectionmaxsize; ++i)
|
for (int i = used; i < sectionmaxsize; ++i)
|
||||||
last *= 10;
|
lastVal *= 10;
|
||||||
}
|
}
|
||||||
// Even those *= 10s can't take last above absMax:
|
// Even those *= 10s can't take last above absMax:
|
||||||
Q_ASSERT(negate ? last >= absMin : last <= absMax);
|
Q_ASSERT(negate ? lastVal >= absMin : lastVal <= absMax);
|
||||||
if (negate ? last > absMax : last < absMin) {
|
if (negate ? lastVal > absMax : lastVal < absMin) {
|
||||||
if (unfilled) {
|
if (unfilled) {
|
||||||
result = ParsedSection(Intermediate, last, used);
|
result = ParsedSection(Intermediate, lastVal, used);
|
||||||
} else if (negate) {
|
} else if (negate) {
|
||||||
QDTPDEBUG << "invalid because" << last << "is greater than absoluteMax"
|
QDTPDEBUG << "invalid because" << lastVal << "is greater than absoluteMax"
|
||||||
<< absMax;
|
<< absMax;
|
||||||
} else {
|
} else {
|
||||||
QDTPDEBUG << "invalid because" << last << "is less than absoluteMin"
|
QDTPDEBUG << "invalid because" << lastVal << "is less than absoluteMin"
|
||||||
<< absMin;
|
<< absMin;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (unfilled && (fi & (FixedWidth | Numeric)) == (FixedWidth | Numeric)) {
|
} else if (unfilled && (fi & (FixedWidth | Numeric)) == (FixedWidth | Numeric)) {
|
||||||
if (skipToNextSection(sectionIndex, defaultValue, digitsStr)) {
|
if (skipToNextSection(sectionIndex, defaultValue, digitsStr)) {
|
||||||
const int missingZeroes = sectionmaxsize - digitsStr.size();
|
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'));
|
m_text.insert(offset, QString(missingZeroes, u'0'));
|
||||||
++(const_cast<QDateTimeParser*>(this)->sectionNodes[sectionIndex].zeroesAdded);
|
++(const_cast<QDateTimeParser*>(this)->sectionNodes[sectionIndex].zeroesAdded);
|
||||||
} else {
|
} else {
|
||||||
result = ParsedSection(Intermediate, last, used);;
|
result = ParsedSection(Intermediate, lastVal, used);;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result = ParsedSection(Acceptable, last, used);
|
result = ParsedSection(Acceptable, lastVal, used);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user