From 61e494195a7bc53f157599800c237bfdade17e14 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 4 Oct 2015 10:58:28 -0400 Subject: [PATCH] ISO8601: Added separate ::isoEnabled settings for ISO8601d and ISO8601p --- src/Context.cpp | 1 + src/ISO8601.cpp | 31 +++++++++++++++++++++++-------- src/ISO8601.h | 3 +++ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index ce709692b..703ff8407 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -633,6 +633,7 @@ void Context::staticInitialization () Task::regex = Variant::searchUsingRegex = config.getBoolean ("regex"); Lexer::dateFormat = Variant::dateFormat = config.get ("dateformat"); Lexer::isoEnabled = Variant::isoEnabled = config.getBoolean ("date.iso"); + ISO8601p::isoEnabled = ISO8601d::isoEnabled = config.getBoolean ("date.iso"); TDB2::debug_mode = config.getBoolean ("debug"); diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index dc3260efc..1378c01d9 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -112,6 +112,8 @@ static struct std::string ISO8601d::weekstart = STRING_DATE_SUNDAY; int ISO8601d::minimumMatchLength = 3; +bool ISO8601d::isoEnabled = true; +bool ISO8601p::isoEnabled = true; //////////////////////////////////////////////////////////////////////////////// ISO8601d::ISO8601d () @@ -233,13 +235,26 @@ bool ISO8601d::parse ( { auto i = start; Nibbler n (input.substr (i)); - if (parse_formatted (n, format) || - parse_date_time (n) || // Strictest first. - parse_date_time_ext (n) || - 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. + if (parse_formatted (n, format)) + { + // Check the values and determine time_t. + if (validate ()) + { + // Record cursor position. + start = n.cursor (); + + resolve (); + return true; + } + } + + else if (ISO8601d::isoEnabled && + (parse_date_time (n) || // Strictest first. + parse_date_time_ext (n) || + 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. { // Check the values and determine time_t. if (validate ()) @@ -252,10 +267,10 @@ bool ISO8601d::parse ( } } - // ::parse_epoch and ::parse_named do not require ::validate and ::resolve. else if (parse_epoch (n) || parse_named (n)) { + // ::validate and ::resolve are not needed in this case. start = n.cursor (); return true; } diff --git a/src/ISO8601.h b/src/ISO8601.h index ff3e76413..b336ccb15 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -36,6 +36,7 @@ class ISO8601d public: static std::string weekstart; static int minimumMatchLength; + static bool isoEnabled; ISO8601d (); ISO8601d (const std::string&, const std::string& format = ""); @@ -138,6 +139,8 @@ public: class ISO8601p { public: + static bool isoEnabled; + ISO8601p (); ISO8601p (time_t); ISO8601p (const std::string&);