diff --git a/src/Date.cpp b/src/Date.cpp index c71112b95..c376f3c14 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -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) { diff --git a/src/Date.h b/src/Date.h index c064f47cf..8676dc44c 100644 --- a/src/Date.h +++ b/src/Date.h @@ -43,8 +43,12 @@ public: Date (const std::string&, const std::string& format = "m/d/Y", const bool iso = true, - const bool epoch = true, - const bool require_depletion = true); + const bool epoch = true); + Date (const std::string&, + std::string::size_type&, + const std::string& format = "m/d/Y", + const bool iso = true, + const bool epoch = true); Date (const Date&); virtual ~Date (); diff --git a/src/Lexer.cpp b/src/Lexer.cpp index 0db3763e1..b37d6eccc 100644 --- a/src/Lexer.cpp +++ b/src/Lexer.cpp @@ -660,17 +660,10 @@ bool Lexer::is_date (std::string& result) { try { - // TODO Why stop at the space? This seems wrong. - std::string::size_type legacy_i = _input.find (' ', _i); - if (legacy_i == std::string::npos) - legacy_i = _input.length (); - - std::string legacy_result = _input.substr (_shift_counter, legacy_i - _shift_counter); - Date legacyDate (legacy_result, Lexer::dateFormat, false, false, false); - - legacy_i -= _shift_counter; + std::string::size_type legacy_i = 0; + Date legacyDate (_input.substr (_shift_counter), legacy_i, Lexer::dateFormat, false, false); + result = _input.substr (_shift_counter, legacy_i); while (legacy_i--) shift (); - result = legacy_result; return true; }