- Added a new date parse method that indicates the length of the parsed item,
  and does not require Nibbler::depletion.
This commit is contained in:
Paul Beckingham 2014-06-29 22:16:44 -04:00
parent 17ffe3d222
commit 0c0e36993d
3 changed files with 59 additions and 16 deletions

View file

@ -131,8 +131,7 @@ Date::Date (
const std::string& input,
const std::string& format /* = "m/d/Y" */,
const bool iso /* = true */,
const bool epoch /* = true */,
const bool require_depletion /* = true */)
const bool epoch /* = true */)
{
// Check first to see if this is supported as a named date.
Variant v;
@ -146,13 +145,13 @@ Date::Date (
Nibbler n (input);
n.save ();
#ifdef NIBBLER_FEATURE_DATE
if (n.getDate (format, _t) && (!require_depletion || n.depleted ()))
if (n.getDate (format, _t) && n.depleted ())
return;
#endif
// Parse an ISO date.
n.restore ();
if (iso && n.getDateISO (_t) && (!require_depletion || n.depleted ()))
if (iso && n.getDateISO (_t) && n.depleted ())
return;
// Perhaps it is an epoch date, in string form?
@ -163,6 +162,53 @@ Date::Date (
throw ::format (STRING_DATE_INVALID_FORMAT, input, format);
}
////////////////////////////////////////////////////////////////////////////////
Date::Date (
const std::string& input,
std::string::size_type& i,
const std::string& format /* = "m/d/Y" */,
const bool iso /* = true */,
const bool epoch /* = true */)
{
// Check first to see if this is supported as a named date.
Variant v;
if (namedDates (input, v))
{
i = v.source ().length ();
_t = v.get_date ();
return;
}
// Parse a formatted date.
Nibbler n (input);
n.save ();
#ifdef NIBBLER_FEATURE_DATE
if (n.getDate (format, _t))
{
i = n.cursor ();
return;
}
#endif
// Parse an ISO date.
n.restore ();
if (iso && n.getDateISO (_t))
{
i = n.cursor ();
return;
}
// Perhaps it is an epoch date, in string form?
n.restore ();
if (epoch && isEpoch (input))
{
i = 10;
return;
}
throw ::format (STRING_DATE_INVALID_FORMAT, input, format);
}
////////////////////////////////////////////////////////////////////////////////
Date::Date (const Date& rhs)
{