mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Nibbler: Removed unused ::getDate and tests
This commit is contained in:
parent
a369d1ed2d
commit
51afff2e6e
3 changed files with 0 additions and 293 deletions
166
src/Nibbler.cpp
166
src/Nibbler.cpp
|
@ -32,9 +32,6 @@
|
|||
#include <Lexer.h>
|
||||
#include <Nibbler.h>
|
||||
#include <util.h>
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
#include <ISO8601.h>
|
||||
#endif
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
#include <RX.h>
|
||||
#endif
|
||||
|
@ -746,169 +743,6 @@ bool Nibbler::parseDigits(
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
bool Nibbler::getDate (const std::string& format, time_t& t)
|
||||
{
|
||||
auto i = _cursor;
|
||||
|
||||
int month = -1; // So we can check later.
|
||||
int day = -1;
|
||||
int year = -1;
|
||||
int hour = -1;
|
||||
int minute = -1;
|
||||
int second = -1;
|
||||
|
||||
// For parsing, unused.
|
||||
int wday = -1;
|
||||
int week = -1;
|
||||
|
||||
for (unsigned int f = 0; f < format.length (); ++f)
|
||||
{
|
||||
switch (format[f])
|
||||
{
|
||||
case 'm':
|
||||
case 'M':
|
||||
if (! parseDigits(i, month, 2, format[f] == 'M'))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'D':
|
||||
if (! parseDigits(i, day, 2, format[f] == 'D'))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
case 'Y':
|
||||
if (! parseDigits(i, year, format[f] == 'y' ? 2 : 4))
|
||||
return false;
|
||||
if (format[f] == 'y')
|
||||
year += 2000;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case 'H':
|
||||
if (! parseDigits(i, hour, 2, format[f] == 'H'))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
case 'N':
|
||||
if (! parseDigits(i, minute, 2, format[f] == 'N'))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
case 'S':
|
||||
if (! parseDigits(i, second, 2, format[f] == 'S'))
|
||||
return false;
|
||||
break;
|
||||
|
||||
// Merely parse, not extract.
|
||||
case 'v':
|
||||
case 'V':
|
||||
if (! parseDigits(i, week, 2, format[f] == 'V'))
|
||||
return false;
|
||||
break;
|
||||
|
||||
// Merely parse, not extract.
|
||||
case 'a':
|
||||
case 'A':
|
||||
if (i + 3 <= _length &&
|
||||
! Lexer::isDigit ((*_input)[i + 0]) &&
|
||||
! Lexer::isDigit ((*_input)[i + 1]) &&
|
||||
! Lexer::isDigit ((*_input)[i + 2]))
|
||||
{
|
||||
wday = ISO8601d::dayOfWeek (_input->substr (i, 3).c_str ());
|
||||
i += (format[f] == 'a') ? 3 : ISO8601d::dayName (wday).size ();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
case 'B':
|
||||
if (i + 3 <= _length &&
|
||||
! Lexer::isDigit ((*_input)[i + 0]) &&
|
||||
! Lexer::isDigit ((*_input)[i + 1]) &&
|
||||
! Lexer::isDigit ((*_input)[i + 2]))
|
||||
{
|
||||
if (month != -1)
|
||||
return false;
|
||||
month = ISO8601d::monthOfYear (_input->substr (i, 3).c_str());
|
||||
i += (format[f] == 'b') ? 3 : ISO8601d::monthName (month).size ();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (i + 1 <= _length &&
|
||||
(*_input)[i] == format[f])
|
||||
++i;
|
||||
else
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// By default, the most global date variables that are undefined are put to
|
||||
// the current date (for instance, the year to the current year for formats
|
||||
// that lack Y/y). If even 'second' is undefined, then the date is parsed as
|
||||
// now.
|
||||
if (year == -1)
|
||||
{
|
||||
ISO8601d now;
|
||||
year = now.year ();
|
||||
if (month == -1)
|
||||
{
|
||||
month = now.month ();
|
||||
if (day == -1)
|
||||
{
|
||||
day = now.day ();
|
||||
if (hour == -1)
|
||||
{
|
||||
hour = now.hour ();
|
||||
if (minute == -1)
|
||||
{
|
||||
minute = now.minute ();
|
||||
if (second == -1)
|
||||
second = now.second ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Put all remaining undefined date variables to their default values (0 or
|
||||
// 1).
|
||||
month = (month == -1) ? 1 : month;
|
||||
day = (day == -1) ? 1 : day;
|
||||
hour = (hour == -1) ? 0 : hour;
|
||||
minute = (minute == -1) ? 0 : minute;
|
||||
second = (second == -1) ? 0 : second;
|
||||
|
||||
// Check that values are correct
|
||||
if (! ISO8601d::valid (month, day, year, hour, minute, second))
|
||||
return false;
|
||||
|
||||
// Convert to epoch.
|
||||
struct tm tms {};
|
||||
tms.tm_isdst = -1; // Requests that mktime determine summer time effect.
|
||||
tms.tm_mon = month - 1;
|
||||
tms.tm_mday = day;
|
||||
tms.tm_year = year - 1900;
|
||||
tms.tm_hour = hour;
|
||||
tms.tm_min = minute;
|
||||
tms.tm_sec = second;
|
||||
|
||||
t = mktime (&tms);
|
||||
_cursor = i;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Assumes that the options are sorted by decreasing length, so that if the
|
||||
// options contain 'fourteen' and 'four', the stream is first matched against
|
||||
|
|
|
@ -27,9 +27,6 @@
|
|||
#ifndef INCLUDED_NIBBLER
|
||||
#define INCLUDED_NIBBLER
|
||||
|
||||
#define NIBBLER_FEATURE_DATE
|
||||
//#undef NIBBLER_FEATURE_DATE
|
||||
|
||||
#define NIBBLER_FEATURE_REGEX
|
||||
//#undef NIBBLER_FEATURE_REGEX
|
||||
|
||||
|
@ -76,9 +73,6 @@ public:
|
|||
bool getPartialUUID (std::string&);
|
||||
bool getDateISO (time_t&);
|
||||
bool parseDigits(std::string::size_type&, int&, unsigned int, bool strict = true);
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
bool getDate (const std::string&, time_t&);
|
||||
#endif
|
||||
bool getOneOf (const std::vector <std::string>&, std::string&);
|
||||
bool getName (std::string&);
|
||||
bool getWord (std::string&);
|
||||
|
|
|
@ -28,9 +28,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <Context.h>
|
||||
#include <Nibbler.h>
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
#include <ISO8601.h>
|
||||
#endif
|
||||
#include <test.h>
|
||||
|
||||
Context context;
|
||||
|
@ -38,18 +35,10 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int, char**)
|
||||
{
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
UnitTest t (410);
|
||||
#else
|
||||
UnitTest t (380);
|
||||
#endif
|
||||
#else
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
UnitTest t (346);
|
||||
#else
|
||||
UnitTest t (322);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Ensure environment has no influence.
|
||||
|
@ -64,9 +53,6 @@ int main (int, char**)
|
|||
double d;
|
||||
time_t ti;
|
||||
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
ISO8601d dt;
|
||||
#endif
|
||||
std::vector <std::string> options;
|
||||
|
||||
// Make sure the nibbler behaves itself with trivial input.
|
||||
|
@ -87,9 +73,6 @@ int main (int, char**)
|
|||
t.notok (n.getUntilEOL (s), "trivial: getUntilEOL");
|
||||
t.notok (n.getUntilEOS (s), "trivial: getUntilEOS");
|
||||
t.notok (n.getDateISO (ti), "trivial: getDateISO");
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
t.notok (n.getDate ("YYYYMMDD", ti), "trivial: getDate");
|
||||
#endif
|
||||
t.notok (n.getOneOf (options, s), "trivial: getOneOf");
|
||||
t.ok (n.depleted (), "trivial: depleted");
|
||||
|
||||
|
@ -528,110 +511,6 @@ int main (int, char**)
|
|||
t.is (ti, 1234567890, "'20090213T233130Z': getDateISO () -> 1234567890");
|
||||
t.ok (n.depleted (), "depleted");
|
||||
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
// bool getDate (time_t&, const std::string&);
|
||||
t.diag ("Nibbler::getDate");
|
||||
n = Nibbler ("1/1/2008");
|
||||
t.ok (n.getDate ("m/d/Y", ti), "m/d/Y ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 1, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 1, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2008, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("20080101");
|
||||
t.ok (n.getDate ("YMD", ti), "YMD ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 1, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 1, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2008, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("12/31/2007");
|
||||
t.ok (n.getDate ("m/d/Y", ti), "m/d/Y ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 12, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 31, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2007, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("20071231");
|
||||
t.ok (n.getDate ("YMD", ti), "YMD ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 12, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 31, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2007, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("Tue 01 Jan 2008 (01)");
|
||||
t.ok (n.getDate ("a D b Y (V)", ti), "a D b Y (V)");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 1, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 1, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2008, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("Tuesday, January 1, 2008");
|
||||
t.ok (n.getDate ("A, B d, Y", ti), "A, B d, Y ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 1, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 1, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2008, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("w01 Tue 2008-01-01");
|
||||
t.ok (n.getDate ("wV a Y-M-D", ti), "wV a Y-M-D ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 1, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 1, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2008, "ctor (std::string) -> y");
|
||||
|
||||
n = Nibbler ("6/7/2010 1:23:45");
|
||||
t.ok (n.getDate ("m/d/Y h:N:S", ti), "m/d/Y h:N:S ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 6, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 7, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2010, "ctor (std::string) -> Y");
|
||||
t.is (dt.hour (), 1, "ctor (std::string) -> h");
|
||||
t.is (dt.minute (), 23, "ctor (std::string) -> N");
|
||||
t.is (dt.second (), 45, "ctor (std::string) -> S");
|
||||
|
||||
n = Nibbler ("6/7/2010 01:23:45");
|
||||
t.ok (n.getDate ("m/d/Y H:N:S", ti), "m/d/Y H:N:S ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 6, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 7, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2010, "ctor (std::string) -> Y");
|
||||
t.is (dt.hour (), 1, "ctor (std::string) -> h");
|
||||
t.is (dt.minute (), 23, "ctor (std::string) -> N");
|
||||
t.is (dt.second (), 45, "ctor (std::string) -> S");
|
||||
|
||||
n = Nibbler ("6/7/2010 12:34:56");
|
||||
t.ok (n.getDate ("m/d/Y H:N:S", ti), "m/d/Y H:N:S ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 6, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 7, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2010, "ctor (std::string) -> Y");
|
||||
t.is (dt.hour (), 12, "ctor (std::string) -> h");
|
||||
t.is (dt.minute (), 34, "ctor (std::string) -> N");
|
||||
t.is (dt.second (), 56, "ctor (std::string) -> S");
|
||||
|
||||
n = Nibbler ("2010");
|
||||
t.ok (n.getDate ("Y", ti), "Y ok");
|
||||
dt = ISO8601d (ti);
|
||||
t.is (dt.month (), 1, "ctor (std::string) -> m");
|
||||
t.is (dt.day (), 1, "ctor (std::string) -> d");
|
||||
t.is (dt.year (), 2010, "ctor (std::string) -> Y");
|
||||
t.is (dt.hour (), 0, "ctor (std::string) -> h");
|
||||
t.is (dt.minute (), 0, "ctor (std::string) -> N");
|
||||
t.is (dt.second (), 0, "ctor (std::string) -> S");
|
||||
|
||||
n = Nibbler ("17:18:19");
|
||||
t.ok (n.getDate ("H:N:S", ti), "H:N:S ok");
|
||||
dt = ISO8601d (ti);
|
||||
ISO8601d now;
|
||||
t.is (dt.month (), now.month(), "ctor (std::string) -> m");
|
||||
t.is (dt.day (), now.day(), "ctor (std::string) -> d");
|
||||
t.is (dt.year (), now.year(), "ctor (std::string) -> Y");
|
||||
t.is (dt.hour (), 17, "ctor (std::string) -> h");
|
||||
t.is (dt.minute (), 18, "ctor (std::string) -> N");
|
||||
t.is (dt.second (), 19, "ctor (std::string) -> S");
|
||||
#endif
|
||||
|
||||
// bool getOneOf (const std::vector <std::string>&, std::string&);
|
||||
t.diag ("Nibbler::getOneOf");
|
||||
options = {"one", "two", "three"};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue