mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 07:43:08 +02:00
[clang-tidy] Simplify boolean expressions
Found with readability-simplify-boolean-expr Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
parent
13e1bf7204
commit
51870dff34
8 changed files with 25 additions and 51 deletions
11
src/CLI2.cpp
11
src/CLI2.cpp
|
@ -1492,11 +1492,9 @@ void CLI2::findIDs ()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string raw = a.attribute ("raw");
|
std::string raw = a.attribute ("raw");
|
||||||
previousFilterArgWasAnOperator = (a._lextype == Lexer::Type::op &&
|
previousFilterArgWasAnOperator = a._lextype == Lexer::Type::op &&
|
||||||
raw != "(" &&
|
raw != "(" &&
|
||||||
raw != ")")
|
raw != ")";
|
||||||
? true
|
|
||||||
: false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1722,10 +1720,7 @@ void CLI2::insertIDExpr ()
|
||||||
bool ascending = true;
|
bool ascending = true;
|
||||||
int low = strtol (r->first.c_str (), nullptr, 10);
|
int low = strtol (r->first.c_str (), nullptr, 10);
|
||||||
int high = strtol (r->second.c_str (), nullptr, 10);
|
int high = strtol (r->second.c_str (), nullptr, 10);
|
||||||
if (low <= high)
|
ascending = low <= high;
|
||||||
ascending = true;
|
|
||||||
else
|
|
||||||
ascending = false;
|
|
||||||
|
|
||||||
reconstructed.push_back (openParen);
|
reconstructed.push_back (openParen);
|
||||||
reconstructed.push_back (argID);
|
reconstructed.push_back (argID);
|
||||||
|
|
|
@ -73,7 +73,7 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
|
||||||
|
|
||||||
// Debug output from Eval during compilation is useful. During evaluation
|
// Debug output from Eval during compilation is useful. During evaluation
|
||||||
// it is mostly noise.
|
// it is mostly noise.
|
||||||
eval.debug (Context::getContext ().config.getInteger ("debug.parser") >= 3 ? true : false);
|
eval.debug (Context::getContext ().config.getInteger ("debug.parser") >= 3);
|
||||||
eval.compileExpression (precompiled);
|
eval.compileExpression (precompiled);
|
||||||
|
|
||||||
for (auto& task : input)
|
for (auto& task : input)
|
||||||
|
@ -124,7 +124,7 @@ void Filter::subset (std::vector <Task>& output)
|
||||||
|
|
||||||
// Debug output from Eval during compilation is useful. During evaluation
|
// Debug output from Eval during compilation is useful. During evaluation
|
||||||
// it is mostly noise.
|
// it is mostly noise.
|
||||||
eval.debug (Context::getContext ().config.getInteger ("debug.parser") >= 3 ? true : false);
|
eval.debug (Context::getContext ().config.getInteger ("debug.parser") >= 3);
|
||||||
eval.compileExpression (precompiled);
|
eval.compileExpression (precompiled);
|
||||||
|
|
||||||
output.clear ();
|
output.clear ();
|
||||||
|
@ -240,16 +240,10 @@ bool Filter::pendingOnly () const
|
||||||
|
|
||||||
if (countStatus)
|
if (countStatus)
|
||||||
{
|
{
|
||||||
if (!countPending && !countWaiting && !countRecurring)
|
return !(!countPending && !countWaiting && !countRecurring);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countId)
|
return countId != 0;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -75,7 +75,7 @@ bool Lexer::token (std::string& token, Lexer::Type& type)
|
||||||
// - path < substitution < pattern
|
// - path < substitution < pattern
|
||||||
// - set < number
|
// - set < number
|
||||||
// - word last
|
// - word last
|
||||||
if (isString (token, type, "'\"") ||
|
return isString (token, type, "'\"") ||
|
||||||
isDate (token, type) ||
|
isDate (token, type) ||
|
||||||
isDuration (token, type) ||
|
isDuration (token, type) ||
|
||||||
isURL (token, type) ||
|
isURL (token, type) ||
|
||||||
|
@ -92,10 +92,7 @@ bool Lexer::token (std::string& token, Lexer::Type& type)
|
||||||
isPattern (token, type) ||
|
isPattern (token, type) ||
|
||||||
isOperator (token, type) ||
|
isOperator (token, type) ||
|
||||||
isIdentifier (token, type) ||
|
isIdentifier (token, type) ||
|
||||||
isWord (token, type))
|
isWord (token, type);
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -266,10 +263,7 @@ void Lexer::dequote (std::string& input, const std::string& quotes)
|
||||||
// escapes, to get them past the shell.
|
// escapes, to get them past the shell.
|
||||||
bool Lexer::wasQuoted (const std::string& input)
|
bool Lexer::wasQuoted (const std::string& input)
|
||||||
{
|
{
|
||||||
if (input.find_first_of (" \t()<>&~") != std::string::npos)
|
return input.find_first_of (" \t()<>&~") != std::string::npos;
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1571,7 +1565,7 @@ bool Lexer::readWord (
|
||||||
prev = c;
|
prev = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return word.length () > 0 ? true : false;
|
return word.length () > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1438,7 +1438,7 @@ int TDB2::id (const std::string& uuid)
|
||||||
bool TDB2::verifyUniqueUUID (const std::string& uuid)
|
bool TDB2::verifyUniqueUUID (const std::string& uuid)
|
||||||
{
|
{
|
||||||
pending.get_tasks ();
|
pending.get_tasks ();
|
||||||
return pending.id (uuid) != 0 ? false : true;
|
return pending.id (uuid) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
14
src/Task.cpp
14
src/Task.cpp
|
@ -190,10 +190,7 @@ void Task::setAsNow (const std::string& att)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Task::has (const std::string& name) const
|
bool Task::has (const std::string& name) const
|
||||||
{
|
{
|
||||||
if (data.find (name) != data.end ())
|
return data.find (name) != data.end ();
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1049,7 +1046,7 @@ int Task::getAnnotationCount () const
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool Task::hasAnnotations () const
|
bool Task::hasAnnotations () const
|
||||||
{
|
{
|
||||||
return annotation_count ? true : false;
|
return annotation_count != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1296,10 +1293,7 @@ bool Task::hasTag (const std::string& tag) const
|
||||||
// Concrete tags.
|
// Concrete tags.
|
||||||
auto tags = split (get ("tags"), ',');
|
auto tags = split (get ("tags"), ',');
|
||||||
|
|
||||||
if (std::find (tags.begin (), tags.end (), tag) != tags.end ())
|
return std::find (tags.begin (), tags.end (), tag) != tags.end ();
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1368,7 +1362,7 @@ void Task::substitute (
|
||||||
const std::string& to,
|
const std::string& to,
|
||||||
const std::string& flags)
|
const std::string& flags)
|
||||||
{
|
{
|
||||||
bool global = (flags.find ('g') != std::string::npos ? true : false);
|
bool global = (flags.find ('g') != std::string::npos);
|
||||||
|
|
||||||
// Get the data to modify.
|
// Get the data to modify.
|
||||||
std::string description = get ("description");
|
std::string description = get ("description");
|
||||||
|
|
|
@ -1820,7 +1820,7 @@ void Variant::cast (const enum type new_type)
|
||||||
case type_integer:
|
case type_integer:
|
||||||
switch (new_type)
|
switch (new_type)
|
||||||
{
|
{
|
||||||
case type_boolean: _bool = _integer == 0 ? false : true; break;
|
case type_boolean: _bool = _integer != 0; break;
|
||||||
case type_integer: break;
|
case type_integer: break;
|
||||||
case type_real: _real = static_cast<double>(_integer); break;
|
case type_real: _real = static_cast<double>(_integer); break;
|
||||||
case type_string:
|
case type_string:
|
||||||
|
@ -1838,7 +1838,7 @@ void Variant::cast (const enum type new_type)
|
||||||
case type_real:
|
case type_real:
|
||||||
switch (new_type)
|
switch (new_type)
|
||||||
{
|
{
|
||||||
case type_boolean: _bool = _real == 0.0 ? false : true; break;
|
case type_boolean: _bool = _real != 0.0; break;
|
||||||
case type_integer: _integer = static_cast<int>(_real); break;
|
case type_integer: _integer = static_cast<int>(_real); break;
|
||||||
case type_real: break;
|
case type_real: break;
|
||||||
case type_string:
|
case type_string:
|
||||||
|
@ -1858,9 +1858,9 @@ void Variant::cast (const enum type new_type)
|
||||||
switch (new_type)
|
switch (new_type)
|
||||||
{
|
{
|
||||||
case type_boolean:
|
case type_boolean:
|
||||||
_bool = (_string.length () == 0 ||
|
_bool = !(_string.length () == 0 ||
|
||||||
_string == "0" ||
|
_string == "0" ||
|
||||||
_string == "0.0") ? false : true;
|
_string == "0.0");
|
||||||
break;
|
break;
|
||||||
case type_integer:
|
case type_integer:
|
||||||
_integer = static_cast<int>(strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10)));
|
_integer = static_cast<int>(strtol (_string.c_str (), nullptr, (_string.substr (0, 2) == "0x" ? 16 : 10)));
|
||||||
|
@ -1913,7 +1913,7 @@ void Variant::cast (const enum type new_type)
|
||||||
case type_date:
|
case type_date:
|
||||||
switch (new_type)
|
switch (new_type)
|
||||||
{
|
{
|
||||||
case type_boolean: _bool = _date != 0 ? true : false; break;
|
case type_boolean: _bool = _date != 0; break;
|
||||||
case type_integer: _integer = static_cast<int>(_date); break;
|
case type_integer: _integer = static_cast<int>(_date); break;
|
||||||
case type_real: _real = static_cast<double>(_date); break;
|
case type_real: _real = static_cast<double>(_date); break;
|
||||||
case type_string: _string = std::string(*this); break;
|
case type_string: _string = std::string(*this); break;
|
||||||
|
@ -1925,7 +1925,7 @@ void Variant::cast (const enum type new_type)
|
||||||
case type_duration:
|
case type_duration:
|
||||||
switch (new_type)
|
switch (new_type)
|
||||||
{
|
{
|
||||||
case type_boolean: _bool = _duration != 0 ? true : false; break;
|
case type_boolean: _bool = _duration != 0; break;
|
||||||
case type_integer: _integer = static_cast<int>(_duration); break;
|
case type_integer: _integer = static_cast<int>(_duration); break;
|
||||||
case type_real: _real = static_cast<double>(_duration); break;
|
case type_real: _real = static_cast<double>(_duration); break;
|
||||||
case type_string: _string = std::string(*this); break;
|
case type_string: _string = std::string(*this); break;
|
||||||
|
|
|
@ -302,7 +302,7 @@ std::string ViewTask::render (std::vector <Task>& data, std::vector <int>& seque
|
||||||
autoColorize (data[sequence[s]], rule_color);
|
autoColorize (data[sequence[s]], rule_color);
|
||||||
|
|
||||||
// Alternate rows based on |s % 2|
|
// Alternate rows based on |s % 2|
|
||||||
bool odd = (s % 2) ? true : false;
|
bool odd = (s % 2) != 0;
|
||||||
Color row_color;
|
Color row_color;
|
||||||
if (Context::getContext ().color ())
|
if (Context::getContext ().color ())
|
||||||
{
|
{
|
||||||
|
|
|
@ -174,11 +174,8 @@ bool generateDueDates (Task& parent, std::vector <Datetime>& allDue)
|
||||||
// parent mask contains all + or X, then there never will be another task
|
// parent mask contains all + or X, then there never will be another task
|
||||||
// to generate, and this parent task may be safely reaped.
|
// to generate, and this parent task may be safely reaped.
|
||||||
auto mask = parent.get ("mask");
|
auto mask = parent.get ("mask");
|
||||||
if (mask.length () == allDue.size () &&
|
return !(mask.length () == allDue.size () &&
|
||||||
mask.find ('-') == std::string::npos)
|
mask.find ('-') == std::string::npos);
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > now)
|
if (i > now)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue