Eliminate in/out arguments from QDateTimeParser::parse()
Its first two arguments were non-const references that it modified. A copy of the first was already being passed back in the returned struct; and the one caller that wanted the modified value was in fact copying this copy back over the QString it had passed in (that was thus equal already). So passing by value is fine. The second's only change was increment by a field I've just added to StateNode in refactoring parse(); so we can let the caller do that adding, instead. Change-Id: I05abb644f3e5a60f94b03292302dd1bbe996cce9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0fdbd239c0
commit
c24ad1896a
@ -1332,15 +1332,14 @@ QDateTimeParser::scanString(const QDateTime &defaultValue,
|
||||
\internal
|
||||
*/
|
||||
|
||||
QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPosition,
|
||||
const QDateTime &defaultValue, bool fixup) const
|
||||
QDateTimeParser::StateNode
|
||||
QDateTimeParser::parse(QString input, int position, const QDateTime &defaultValue, bool fixup) const
|
||||
{
|
||||
const QDateTime minimum = getMinimum();
|
||||
const QDateTime maximum = getMaximum();
|
||||
|
||||
QDTPDEBUG << "parse" << input;
|
||||
StateNode scan = scanString(defaultValue, fixup, &input);
|
||||
cursorPosition += scan.padded;
|
||||
QDTPDEBUGN("'%s' => '%s'(%s)", input.toLatin1().constData(),
|
||||
scan.value.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")).toLatin1().constData(),
|
||||
stateName(scan.state).toLatin1().constData());
|
||||
@ -1440,7 +1439,7 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos
|
||||
}
|
||||
|
||||
int max = toMax != -1 ? getDigit(maximum, i) : absoluteMax(i, scan.value);
|
||||
int pos = cursorPosition - sn.pos;
|
||||
int pos = position + scan.padded - sn.pos;
|
||||
if (pos < 0 || pos >= t.size())
|
||||
pos = -1;
|
||||
if (!potentialValue(t.simplified(), min, max, i, scan.value, pos)) {
|
||||
@ -1936,9 +1935,7 @@ QString QDateTimeParser::stateName(State s) const
|
||||
bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) const
|
||||
{
|
||||
QDateTime val(QDate(1900, 1, 1), QDATETIMEEDIT_TIME_MIN);
|
||||
QString text = t;
|
||||
int copy = -1;
|
||||
const StateNode tmp = parse(text, copy, val, false);
|
||||
const StateNode tmp = parse(t, -1, val, false);
|
||||
if (tmp.state != Acceptable || tmp.conflicts) {
|
||||
return false;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
};
|
||||
|
||||
#ifndef QT_NO_DATESTRING
|
||||
StateNode parse(QString &input, int &cursorPosition, const QDateTime &defaultValue, bool fixup) const;
|
||||
StateNode parse(QString input, int position, const QDateTime &defaultValue, bool fixup) const;
|
||||
bool fromString(const QString &text, QDate *date, QTime *time) const;
|
||||
#endif
|
||||
bool parseFormat(const QString &format);
|
||||
|
@ -1923,6 +1923,7 @@ QDateTime QDateTimeEditPrivate::validateAndInterpret(QString &input, int &positi
|
||||
}
|
||||
StateNode tmp = parse(input, position, value.toDateTime(), fixup);
|
||||
input = tmp.input;
|
||||
position += tmp.padded;
|
||||
state = QValidator::State(int(tmp.state));
|
||||
if (state == QValidator::Acceptable) {
|
||||
if (tmp.conflicts && conflictGuard != tmp.value) {
|
||||
|
Loading…
Reference in New Issue
Block a user