Nibbler: Removed unused ::getDateISO method

This commit is contained in:
Paul Beckingham 2015-10-28 20:13:55 -04:00
parent 51afff2e6e
commit 741afd2240
3 changed files with 2 additions and 87 deletions

View file

@ -632,75 +632,6 @@ bool Nibbler::getPartialUUID (std::string& result)
return false;
}
////////////////////////////////////////////////////////////////////////////////
// 19980119T070000Z = YYYYMMDDThhmmssZ
bool Nibbler::getDateISO (time_t& t)
{
auto i = _cursor;
if (i < _length &&
_length - i >= 16)
{
if (Lexer::isDigit ((*_input)[i + 0]) &&
Lexer::isDigit ((*_input)[i + 1]) &&
Lexer::isDigit ((*_input)[i + 2]) &&
Lexer::isDigit ((*_input)[i + 3]) &&
Lexer::isDigit ((*_input)[i + 4]) &&
Lexer::isDigit ((*_input)[i + 5]) &&
Lexer::isDigit ((*_input)[i + 6]) &&
Lexer::isDigit ((*_input)[i + 7]) &&
(*_input)[i + 8] == 'T' &&
Lexer::isDigit ((*_input)[i + 9]) &&
Lexer::isDigit ((*_input)[i + 10]) &&
Lexer::isDigit ((*_input)[i + 11]) &&
Lexer::isDigit ((*_input)[i + 12]) &&
Lexer::isDigit ((*_input)[i + 13]) &&
Lexer::isDigit ((*_input)[i + 14]) &&
(*_input)[i + 15] == 'Z')
{
_cursor += 16;
int year = ((*_input)[i + 0] - '0') * 1000
+ ((*_input)[i + 1] - '0') * 100
+ ((*_input)[i + 2] - '0') * 10
+ ((*_input)[i + 3] - '0');
int month = ((*_input)[i + 4] - '0') * 10
+ ((*_input)[i + 5] - '0');
int day = ((*_input)[i + 6] - '0') * 10
+ ((*_input)[i + 7] - '0');
int hour = ((*_input)[i + 9] - '0') * 10
+ ((*_input)[i + 10] - '0');
int minute = ((*_input)[i + 11] - '0') * 10
+ ((*_input)[i + 12] - '0');
int second = ((*_input)[i + 13] - '0') * 10
+ ((*_input)[i + 14] - '0');
// 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;
#ifdef HAVE_TM_GMTOFF
tms.tm_gmtoff = 0;
#endif
t = timegm (&tms);
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
// Parse the longest integer using the next 'limit' characters of 'result'
// following position 'i' (when strict is true, the number of digits must be

View file

@ -71,7 +71,6 @@ public:
#endif
bool getUUID (std::string&);
bool getPartialUUID (std::string&);
bool getDateISO (time_t&);
bool parseDigits(std::string::size_type&, int&, unsigned int, bool strict = true);
bool getOneOf (const std::vector <std::string>&, std::string&);
bool getName (std::string&);

View file

@ -36,9 +36,9 @@ Context context;
int main (int, char**)
{
#ifdef NIBBLER_FEATURE_REGEX
UnitTest t (346);
UnitTest t (339);
#else
UnitTest t (322);
UnitTest t (315);
#endif
// Ensure environment has no influence.
@ -51,8 +51,6 @@ int main (int, char**)
std::string s;
int i;
double d;
time_t ti;
std::vector <std::string> options;
// Make sure the nibbler behaves itself with trivial input.
@ -72,7 +70,6 @@ int main (int, char**)
t.notok (n.getUnsignedInt (i), "trivial: getUnsignedInt");
t.notok (n.getUntilEOL (s), "trivial: getUntilEOL");
t.notok (n.getUntilEOS (s), "trivial: getUntilEOS");
t.notok (n.getDateISO (ti), "trivial: getDateISO");
t.notok (n.getOneOf (options, s), "trivial: getOneOf");
t.ok (n.depleted (), "trivial: depleted");
@ -499,18 +496,6 @@ int main (int, char**)
t.is (s, "a0b1c2d3", "partial uuid [8] -> correct");
t.ok (n.depleted (), "not depleted");
// bool getDateISO (time_t&);
t.diag ("Nibbler::getDateISO");
n = Nibbler ("19980119T070000Z");
t.ok (n.getDateISO (ti), "'19980119T070000Z': getDateISO () -> true");
t.is (ti, 885193200, "'19980119T070000Z': getDateISO () -> 885193200");
t.ok (n.depleted (), "depleted");
n = Nibbler ("20090213T233130Z");
t.ok (n.getDateISO (ti), "'20090213T233130Z': getDateISO () -> true");
t.is (ti, 1234567890, "'20090213T233130Z': getDateISO () -> 1234567890");
t.ok (n.depleted (), "depleted");
// bool getOneOf (const std::vector <std::string>&, std::string&);
t.diag ("Nibbler::getOneOf");
options = {"one", "two", "three"};