ColTypeString: Added validate() in ::modify

This commit is contained in:
Paul Beckingham 2016-02-01 23:57:10 -05:00
parent db7ebf9029
commit 4b37fea21f
2 changed files with 28 additions and 17 deletions

View file

@ -28,6 +28,7 @@
- TW-1705 Directories in .task/hooks should not be reported as invalid hooks - TW-1705 Directories in .task/hooks should not be reported as invalid hooks
(thanks to Tomas Babej). (thanks to Tomas Babej).
- TW-1714 Starting recurring task starts all recurrences (thanks to Robin Green). - TW-1714 Starting recurring task starts all recurrences (thanks to Robin Green).
- TW-1718 String UDA not passed through unchanged (thanks to Wim Schuermann).
- TW-1719 Description cannot contain improper ordinals (thanks to Ben Boeckel). - TW-1719 Description cannot contain improper ordinals (thanks to Ben Boeckel).
- TW-1720 CmdContext uses a mix of both throw and std::cout to convey - TW-1720 CmdContext uses a mix of both throw and std::cout to convey
errors (thanks to Paul Beckingham). errors (thanks to Paul Beckingham).

View file

@ -64,31 +64,41 @@ void ColumnTypeString::render (
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void ColumnTypeString::modify (Task& task, const std::string& value) void ColumnTypeString::modify (Task& task, const std::string& value)
{ {
// Try to evaluate 'value'. It might work. std::string label = " MODIFICATION ";
Variant evaluatedValue;
try // Only if it's a DOM ref, eval it first.
Lexer lexer (value);
std::string domRef;
Lexer::Type type;
if (lexer.token (domRef, type) &&
type == Lexer::Type::dom)
{ {
Eval e; Eval e;
e.addSource (domSource); e.addSource (domSource);
e.addSource (namedDates); e.addSource (namedDates);
contextTask = task; contextTask = task;
e.evaluateInfixExpression (value, evaluatedValue);
}
catch (...) Variant v;
{ e.evaluateInfixExpression (value, v);
evaluatedValue = Variant (value); std::string strValue = (std::string) v;
} if (validate (strValue))
{
std::string label = " MODIFICATION "; task.set (_name, strValue);
std::string strValue = (std::string) evaluatedValue; context.debug (label + _name + " <-- '" + strValue + "' <-- '" + value + "'");
if (validate (strValue)) }
{ else
context.debug (label + _name + " <-- '" + strValue + "' <-- '" + value + "'"); throw format (STRING_INVALID_MOD, _name, value);
task.set (_name, strValue);
} }
else else
throw format (STRING_INVALID_MOD, _name, value); {
if (validate (value))
{
task.set (_name, value);
context.debug (label + _name + " <-- '" + value + "'");
}
else
throw format (STRING_INVALID_MOD, _name, value);
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////