mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Lexer
- Replaced old digitsOnly() function with Lexer::isAllDigits.
This commit is contained in:
parent
9f82926c65
commit
26aff348d2
7 changed files with 9 additions and 26 deletions
|
@ -1345,7 +1345,7 @@ void CLI::findIDs ()
|
|||
|
||||
if (terms.size () == 1)
|
||||
{
|
||||
if (! digitsOnly (terms[0]))
|
||||
if (! Lexer::isAllDigits (terms[0]))
|
||||
{
|
||||
is_an_id = false;
|
||||
break;
|
||||
|
@ -1366,8 +1366,8 @@ void CLI::findIDs ()
|
|||
}
|
||||
else if (terms.size () == 2)
|
||||
{
|
||||
if (! digitsOnly (terms[0]) ||
|
||||
! digitsOnly (terms[1]))
|
||||
if (! Lexer::isAllDigits (terms[0]) ||
|
||||
! Lexer::isAllDigits (terms[1]))
|
||||
{
|
||||
is_an_id = false;
|
||||
break;
|
||||
|
@ -2206,7 +2206,7 @@ bool CLI::isIDSequence (const std::string& raw) const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool CLI::isID (const std::string& raw) const
|
||||
{
|
||||
return digitsOnly (raw);
|
||||
return Lexer::isAllDigits (raw);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -823,7 +823,7 @@ void Date::operator++ (int)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Date::isEpoch (const std::string& input)
|
||||
{
|
||||
if (digitsOnly (input) &&
|
||||
if (Lexer::isAllDigits (input) &&
|
||||
input.length () <= 10 )
|
||||
{
|
||||
_t = (time_t) atoi (input.c_str ());
|
||||
|
|
|
@ -107,7 +107,7 @@ Duration::Duration (time_t input)
|
|||
Duration::Duration (const std::string& input)
|
||||
: _secs (0)
|
||||
{
|
||||
if (digitsOnly (input))
|
||||
if (Lexer::isAllDigits (input))
|
||||
{
|
||||
time_t value = (time_t) strtol (input.c_str (), NULL, 10);
|
||||
if (value == 0 || value > 60)
|
||||
|
|
|
@ -120,11 +120,11 @@ int CmdCalendar::execute (std::string& output)
|
|||
argWholeYear = true;
|
||||
|
||||
// YYYY.
|
||||
else if (digitsOnly (*arg) && arg->length () == 4)
|
||||
else if (Lexer::isAllDigits (*arg) && arg->length () == 4)
|
||||
argYear = strtol (arg->c_str (), NULL, 10);
|
||||
|
||||
// MM.
|
||||
else if (digitsOnly (*arg) && arg->length () <= 2)
|
||||
else if (Lexer::isAllDigits (*arg) && arg->length () <= 2)
|
||||
{
|
||||
argMonth = strtol (arg->c_str (), NULL, 10);
|
||||
if (argMonth < 1 || argMonth > 12)
|
||||
|
|
10
src/text.cpp
10
src/text.cpp
|
@ -479,16 +479,6 @@ bool nontrivial (const std::string& input)
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool digitsOnly (const std::string& input)
|
||||
{
|
||||
for (size_t i = 0; i < input.length (); ++i)
|
||||
if (!isdigit (input[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Override of ispunct, that considers #, $ and @ not to be punctuation.
|
||||
//
|
||||
|
|
|
@ -50,7 +50,6 @@ const std::string str_replace (std::string&, const std::string&, const std::stri
|
|||
const std::string str_replace (const std::string&, const std::string&, const std::string&);
|
||||
const char* optionalBlankLine ();
|
||||
bool nontrivial (const std::string&);
|
||||
bool digitsOnly (const std::string&);
|
||||
bool isPunctuation (char);
|
||||
bool compare (const std::string&, const std::string&, bool sensitive = true);
|
||||
bool closeEnough (const std::string&, const std::string&, unsigned int minLength = 0);
|
||||
|
|
|
@ -37,7 +37,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (209);
|
||||
UnitTest t (205);
|
||||
|
||||
// Ensure environment has no influence.
|
||||
unsetenv ("TASKDATA");
|
||||
|
@ -290,12 +290,6 @@ int main (int argc, char** argv)
|
|||
t.ok (nontrivial (" \t\ta"), "nontrivial ' \\t\\ta' -> true");
|
||||
t.ok (nontrivial ("a\t\t "), "nontrivial 'a\\t\\t ' -> true");
|
||||
|
||||
// bool digitsOnly (const std::string&);
|
||||
t.ok (digitsOnly (""), "digitsOnly '' -> true");
|
||||
t.ok (digitsOnly ("0"), "digitsOnly '0' -> true");
|
||||
t.ok (digitsOnly ("123"), "digitsOnly '123' -> true");
|
||||
t.notok (digitsOnly ("12fa"), "digitsOnly '12fa' -> false");
|
||||
|
||||
// bool compare (const std::string&, const std::string&, bool caseless = false);
|
||||
// Make sure degenerate cases are handled.
|
||||
t.ok (compare ("", ""), "'' == ''");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue