Code Cleanup
- Keep date formatting intact in arguments (necessary if the initial string contains optional information, as start or end of day).
This commit is contained in:
committed by
Paul Beckingham
parent
ec330921de
commit
e9abac1d0f
24
src/A3.cpp
24
src/A3.cpp
@@ -694,9 +694,6 @@ const A3 A3::tokenize (const A3& input) const
|
||||
// List of operators for recognition.
|
||||
std::vector <std::string> operators = A3::operator_list ();
|
||||
|
||||
// Date format, for both parsing and rendering.
|
||||
std::string date_format = context.config.get ("dateformat");
|
||||
|
||||
// Nibble them apart.
|
||||
A3 output;
|
||||
Nibbler n (combined);
|
||||
@@ -757,9 +754,9 @@ const A3 A3::tokenize (const A3& input) const
|
||||
// Must be higher than number.
|
||||
// Must be higher than operator.
|
||||
// Note that Nibbler::getDate does not read durations.
|
||||
else if (n.getDate (date_format, t))
|
||||
else if (is_date (n, s))
|
||||
{
|
||||
output.push_back (Arg (Date (t).toString (date_format), Arg::type_date, Arg::cat_literal));
|
||||
output.push_back (Arg (s, Arg::type_date, Arg::cat_literal));
|
||||
if (found_sequence)
|
||||
found_something_after_sequence = true;
|
||||
}
|
||||
@@ -1569,6 +1566,23 @@ bool A3::is_dom (Nibbler& n, Arg& arg)
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool A3::is_date (Nibbler& n, std::string& result)
|
||||
{
|
||||
std::string date_format = context.config.get ("dateformat");
|
||||
std::string::size_type start = n.save ();
|
||||
time_t t;
|
||||
|
||||
if (n.getDate (date_format, t))
|
||||
{
|
||||
result = n.str ().substr (start, n.cursor () - start);
|
||||
return true;
|
||||
}
|
||||
|
||||
n.restore ();
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// A duration may only be followed by \0, ), +, -, *, / or ' '.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user