From abbebf69ad4f953142b72857a2c33a51c38f0db6 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 4 Oct 2015 10:43:44 -0400 Subject: [PATCH] ISO8601d: ::parse_named can also skip ::validate and ::resolve --- src/Dates.cpp | 53 +++++++++++++++++++++++++------------------------ src/ISO8601.cpp | 16 ++++++++------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/Dates.cpp b/src/Dates.cpp index e4238c7bb..8c7f17ca6 100644 --- a/src/Dates.cpp +++ b/src/Dates.cpp @@ -103,32 +103,33 @@ static void midsommarafton (struct tm* t) } //////////////////////////////////////////////////////////////////////////////// -// -// -// Nth -// socy, eocy -// socq, eocq -// socm, eocm -// som, eom -// soq, eoq -// soy, eoy -// socw, eocw -// sow, eow -// soww, eoww -// sod, eod -// yesterday -// today -// now -// tomorrow -// later = midnight, Jan 18th, 2038. -// someday = midnight, Jan 18th, 2038. -// easter -// eastermonday -// ascension -// pentecost -// goodfriday -// midsommar = midnight, 1st Saturday after 20th June -// midsommarafton = midnight, 1st Friday after 19th June +// Note how these are all single words: +// +// +// Nth +// socy, eocy +// socq, eocq +// socm, eocm +// som, eom +// soq, eoq +// soy, eoy +// socw, eocw +// sow, eow +// soww, eoww +// sod, eod +// yesterday +// today +// now +// tomorrow +// later = midnight, Jan 18th, 2038. +// someday = midnight, Jan 18th, 2038. +// easter +// eastermonday +// ascension +// pentecost +// goodfriday +// midsommar = midnight, 1st Saturday after 20th June +// midsommarafton = midnight, 1st Friday after 19th June // bool namedDates (const std::string& name, Variant& value) { diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index d9c09e626..efdf2b052 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -239,8 +239,7 @@ bool ISO8601d::parse ( parse_date_ext (n) || parse_time_utc_ext (n) || parse_time_off_ext (n) || - parse_time_ext (n) || // Time last, as it is the most permissive. - parse_named (n)) + parse_time_ext (n)) // Time last, as it is the most permissive. { // Check the values and determine time_t. if (validate ()) @@ -253,8 +252,9 @@ bool ISO8601d::parse ( } } - // ::parse_epoch doesn't require ::validate and ::resolve. - else if (parse_epoch (n)) + // ::parse_epoch and ::parse_named do not require ::validate and ::resolve. + else if (parse_epoch (n) || + parse_named (n)) { start = n.cursor (); return true; @@ -575,14 +575,16 @@ bool ISO8601d::parse_formatted (Nibbler& n, const std::string& format) //////////////////////////////////////////////////////////////////////////////// bool ISO8601d::parse_named (Nibbler& n) { -/* Variant v; - if (namedDates (input, v)) + if (namedDates (n.str ().substr (n.cursor ()), v)) { + // Advance n by the length of the found item. + std::string dummy; + n.getUntilEOS (dummy); + _date = v.get_date (); return true; } -*/ return false; }