Bug - Durations

- Duration were parsed as <int><unit> in A3, whereas <number><unit> is
  correct.
- Added Nibbler::str method for internal access.
- Nibbler::save, ::restore now return positions.  Useful for extracting
  substrings.
- Modified countdown.t to use the (now) correct units for durations.
This commit is contained in:
Paul Beckingham 2011-08-17 00:45:09 -04:00
parent ee2960b9b0
commit 08fcb5362e
5 changed files with 39 additions and 16 deletions

View file

@ -1471,14 +1471,15 @@ bool A3::is_dom (Nibbler& n, std::string& result)
// This prevents the interpretation of '31st' as a duration ('31s').
bool A3::is_duration (Nibbler& n, std::string& result)
{
n.save ();
std::string::size_type start = n.save ();
int quantity;
int i;
double d;
std::string unit;
std::vector <std::string> units = Duration::get_units ();
if (n.getInt (quantity) &&
if ((n.getInt (i) ||
n.getNumber (d)) &&
n.getOneOf (units, unit))
{
char next = n.next ();
@ -1486,7 +1487,7 @@ bool A3::is_duration (Nibbler& n, std::string& result)
next == ')' ||
next == ' ')
{
result = format (quantity) + unit;
result = n.str ().substr (start, n.cursor () - start);
return true;
}
}

View file

@ -52,23 +52,27 @@ static const char* durations[] =
"d",
"fortnight",
"hours",
"hour",
"hrs",
"hr",
"h",
"minutes",
"mins",
"min",
"mnths",
"monthly",
"months",
"month",
"mnths",
"mths",
"mth",
"mos",
"mo",
"mths",
"m",
"quarterly",
"quarters",
"qrtrs",
"qtrs",
"qtr",
"q",
"seconds",
"secs",
@ -79,11 +83,15 @@ static const char* durations[] =
"weekdays",
"weekly",
"weeks",
"week",
"wks",
"wk",
"w",
"yearly",
"years",
"year",
"yrs",
"yr",
"y",
"-",
};
@ -393,7 +401,9 @@ void Duration::parse (const std::string& input)
else if (match == "yearly") mSecs = (int) (value * 86400 * 365);
else if (match == "annual") mSecs = (int) (value * 86400 * 365);
else if (match == "years") mSecs = (int) (value * 86400 * 365);
else if (match == "year") mSecs = (int) (value * 86400 * 365);
else if (match == "yrs") mSecs = (int) (value * 86400 * 365);
else if (match == "yr") mSecs = (int) (value * 86400 * 365);
else if (match == "y") mSecs = (int) (value * 86400 * 365);
else if (match == "semiannual") mSecs = (int) (value * 86400 * 183);
@ -403,6 +413,7 @@ void Duration::parse (const std::string& input)
else if (match == "quarters") mSecs = (int) (value * 86400 * 91);
else if (match == "qrtrs") mSecs = (int) (value * 86400 * 91);
else if (match == "qtrs") mSecs = (int) (value * 86400 * 91);
else if (match == "qtr") mSecs = (int) (value * 86400 * 91);
else if (match == "q") mSecs = (int) (value * 86400 * 91);
else if (match == "monthly") mSecs = (int) (value * 86400 * 30);
@ -412,6 +423,7 @@ void Duration::parse (const std::string& input)
else if (match == "mos") mSecs = (int) (value * 86400 * 30);
else if (match == "mo") mSecs = (int) (value * 86400 * 30);
else if (match == "mths") mSecs = (int) (value * 86400 * 30);
else if (match == "mth") mSecs = (int) (value * 86400 * 30);
else if (match == "m") mSecs = (int) (value * 86400 * 30);
else if (match == "biweekly") mSecs = (int) (value * 86400 * 14);
@ -420,7 +432,9 @@ void Duration::parse (const std::string& input)
else if (match == "weekly") mSecs = (int) (value * 86400 * 7);
else if (match == "sennight") mSecs = (int) (value * 86400 * 7);
else if (match == "weeks") mSecs = (int) (value * 86400 * 7);
else if (match == "week") mSecs = (int) (value * 86400 * 7);
else if (match == "wks") mSecs = (int) (value * 86400 * 7);
else if (match == "wk") mSecs = (int) (value * 86400 * 7);
else if (match == "w") mSecs = (int) (value * 86400 * 7);
else if (match == "daily") mSecs = (int) (value * 86400 * 1);
@ -430,7 +444,9 @@ void Duration::parse (const std::string& input)
else if (match == "d") mSecs = (int) (value * 86400 * 1);
else if (match == "hours") mSecs = (int) (value * 3600);
else if (match == "hour") mSecs = (int) (value * 3600);
else if (match == "hrs") mSecs = (int) (value * 3600);
else if (match == "hr") mSecs = (int) (value * 3600);
else if (match == "h") mSecs = (int) (value * 3600);
else if (match == "minutes") mSecs = (int) (value * 60);

View file

@ -1116,15 +1116,21 @@ std::string Nibbler::next (const int quantity)
}
////////////////////////////////////////////////////////////////////////////////
void Nibbler::save ()
std::string::size_type Nibbler::save ()
{
mSaved = mCursor;
return mSaved = mCursor;
}
////////////////////////////////////////////////////////////////////////////////
void Nibbler::restore ()
std::string::size_type Nibbler::restore ()
{
mCursor = mSaved;
return mCursor = mSaved;
}
////////////////////////////////////////////////////////////////////////////////
const std::string& Nibbler::str () const
{
return mInput;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -80,9 +80,9 @@ public:
std::string next (const int quantity);
std::string::size_type cursor ();
void save ();
void restore ();
std::string::size_type save ();
std::string::size_type restore ();
const std::string& str () const;
bool depleted ();

View file

@ -47,13 +47,13 @@ if (open my $fh, '>', 'countdown.rc')
print $fh "report.down.sort=due-\n";
print $fh "report.upc.description=countdown_compact+ report\n";
print $fh "report.upc.columns=id,countdown_compact,description\n";
print $fh "report.upc.columns=id,due.countdown,description\n";
print $fh "report.upc.labels=ID,Countdown,Description\n";
print $fh "report.upc.filter=status:pending\n";
print $fh "report.upc.sort=due+\n";
print $fh "report.downc.description=countdown_compact- report\n";
print $fh "report.downc.columns=id,countdown_compact,description\n";
print $fh "report.downc.columns=id,due.countdown,description\n";
print $fh "report.downc.labels=ID,Countdown,Description\n";
print $fh "report.downc.filter=status:pending\n";
print $fh "report.downc.sort=due-\n";