[clang-tidy] Use .empty instead of comparing size

Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev
2019-09-27 19:12:49 -07:00
committed by Paul Beckingham
parent d43fa66489
commit a331cceded
18 changed files with 132 additions and 132 deletions

View File

@@ -653,7 +653,7 @@ void Task::parseJSON (const json::object* root_obj)
{
// If the attribute is a recognized column.
std::string type = Task::attributes[i.first];
if (type != "")
if (!type.empty())
{
// Any specified id is ignored.
if (i.first == "id")
@@ -678,7 +678,7 @@ void Task::parseJSON (const json::object* root_obj)
auto text = i.second->dump ();
Lexer::dequote (text);
Datetime d (text);
set (i.first, text == "" ? "" : d.toEpochString ());
set (i.first, text.empty() ? "" : d.toEpochString ());
}
// Tags are an array of JSON strings.
@@ -840,11 +840,11 @@ std::string Task::composeF4 () const
{
// Orphans have no type, treat as string.
std::string type = Task::attributes[it.first];
if (type == "")
if (type.empty())
type = "string";
// If there is a value.
if (it.second != "")
if (!it.second.empty())
{
ff4 += (first ? "" : " ");
ff4 += it.first;
@@ -883,14 +883,14 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
continue;
// If value is an empty string, do not ever output it
if (i.second == "")
if (i.second.empty())
continue;
if (attributes_written)
out << ',';
std::string type = Task::attributes[i.first];
if (type == "")
if (type.empty())
type = "string";
// Date fields are written as ISO 8601.
@@ -901,7 +901,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
<< (i.first == "modification" ? "modified" : i.first)
<< "\":\""
// Date was deleted, do not export parsed empty string
<< (i.second == "" ? "" : d.toISO ())
<< (i.second.empty() ? "" : d.toISO ())
<< '"';
++attributes_written;
@@ -1124,7 +1124,7 @@ void Task::addDependency (int depid)
{
// Check that id is resolvable.
std::string uuid = Context::getContext ().tdb2.pending.uuid (depid);
if (uuid == "")
if (uuid.empty())
throw format ("Could not create a dependency on task {1} - not found.", depid);
std::string depends = get ("depends");
@@ -1146,7 +1146,7 @@ void Task::addDependency (const std::string& uuid)
// Store the dependency.
std::string depends = get ("depends");
if (depends != "")
if (!depends.empty())
{
// Check for extant dependency.
if (depends.find (uuid) == std::string::npos)
@@ -1193,7 +1193,7 @@ void Task::removeDependency (int id)
{
std::string depends = get ("depends");
std::string uuid = Context::getContext ().tdb2.pending.uuid (id);
if (uuid != "" && depends.find (uuid) != std::string::npos)
if (!uuid.empty() && depends.find (uuid) != std::string::npos)
removeDependency (uuid);
else
throw format ("Could not delete a dependency on task {1} - not found.", id);
@@ -1491,13 +1491,13 @@ void Task::substitute (
void Task::validate (bool applyDefault /* = true */)
{
Task::status status = Task::pending;
if (get ("status") != "")
if (!get ("status").empty())
status = getStatus ();
// 1) Provide missing attributes where possible
// Provide a UUID if necessary. Validate if present.
std::string uid = get ("uuid");
if (has ("uuid") && uid != "")
if (has ("uuid") && !uid.empty())
{
Lexer lex (uid);
std::string token;
@@ -1513,8 +1513,8 @@ void Task::validate (bool applyDefault /* = true */)
if (status == Task::pending &&
has ("due") &&
has ("recur") &&
(! has ("parent") || get ("parent") == "") &&
(! has ("template") || get ("template") == ""))
(! has ("parent") || get ("parent").empty()) &&
(! has ("template") || get ("template").empty()))
{
status = Task::recurring;
}
@@ -1532,16 +1532,16 @@ void Task::validate (bool applyDefault /* = true */)
// Tasks with a wait: date get a special status.
else if (status == Task::pending &&
has ("wait") &&
get ("wait") != "")
!get ("wait").empty())
status = Task::waiting;
// By default, tasks are pending.
else if (! has ("status") || get ("status") == "")
else if (! has ("status") || get ("status").empty())
status = Task::pending;
// Default to 'periodic' type recurrence.
if (status == Task::recurring &&
(! has ("rtype") || get ("rtype") == ""))
(! has ("rtype") || get ("rtype").empty()))
{
set ("rtype", "periodic");
}
@@ -1551,26 +1551,26 @@ void Task::validate (bool applyDefault /* = true */)
#ifdef PRODUCT_TASKWARRIOR
// Provide an entry date unless user already specified one.
if (! has ("entry") || get ("entry") == "")
if (! has ("entry") || get ("entry").empty())
setAsNow ("entry");
// Completed tasks need an end date, so inherit the entry date.
if ((status == Task::completed || status == Task::deleted) &&
(! has ("end") || get ("end") == ""))
(! has ("end") || get ("end").empty()))
setAsNow ("end");
// Pending tasks cannot have an end date, remove if present
if ((status == Task::pending) && (get ("end") != ""))
if ((status == Task::pending) && (!get ("end").empty()))
remove ("end");
// Provide an entry date unless user already specified one.
if (! has ("modified") || get ("modified") == "")
if (! has ("modified") || get ("modified").empty())
setAsNow ("modified");
if (applyDefault && (! has ("parent") || get ("parent") == ""))
if (applyDefault && (! has ("parent") || get ("parent").empty()))
{
// Override with default.project, if not specified.
if (Task::defaultProject != "" &&
if (!Task::defaultProject.empty() &&
! has ("project"))
{
if (Context::getContext ().columns["project"]->validate (Task::defaultProject))
@@ -1578,7 +1578,7 @@ void Task::validate (bool applyDefault /* = true */)
}
// Override with default.due, if not specified.
if (Task::defaultDue != "" &&
if (!Task::defaultDue.empty() &&
! has ("due"))
{
if (Context::getContext ().columns["due"]->validate (Task::defaultDue))
@@ -1592,7 +1592,7 @@ void Task::validate (bool applyDefault /* = true */)
}
// Override with default.scheduled, if not specified.
if (Task::defaultScheduled != "" &&
if (!Task::defaultScheduled.empty() &&
! has ("scheduled"))
{
if (Context::getContext ().columns["scheduled"]->validate (Task::defaultScheduled))
@@ -1620,7 +1620,7 @@ void Task::validate (bool applyDefault /* = true */)
}
}
if (udas.size ())
if (!udas.empty())
{
// For each of those, setup the default value on the task now,
// of course only if we don't have one on the command line already
@@ -1629,7 +1629,7 @@ void Task::validate (bool applyDefault /* = true */)
std::string defVal= Context::getContext ().config.get ("uda." + uda + ".default");
// If the default is empty, or we already have a value, skip it
if (defVal != "" && get (uda) == "")
if (!defVal.empty() && get (uda).empty())
set (uda, defVal);
}
}
@@ -1652,18 +1652,18 @@ void Task::validate (bool applyDefault /* = true */)
// There is no fixing a missing description.
if (! has ("description"))
throw std::string ("A task must have a description.");
else if (get ("description") == "")
else if (get ("description").empty())
throw std::string ("Cannot add a task that is blank.");
// Cannot have a recur frequency with no due date - when would it recur?
if (has ("recur") && (! has ("due") || get ("due") == ""))
if (has ("recur") && (! has ("due") || get ("due").empty()))
throw std::string ("A recurring task must also have a 'due' date.");
// Recur durations must be valid.
if (has ("recur"))
{
std::string value = get ("recur");
if (value != "")
if (!value.empty())
{
Duration p;
std::string::size_type i = 0;
@@ -2074,13 +2074,13 @@ void Task::modify (modType type, bool text_required /* = false */)
// 'value' requires eval.
std::string name = a.attribute ("canonical");
std::string value = a.attribute ("value");
if (value == "" ||
if (value.empty() ||
value == "''" ||
value == "\"\"")
{
// ::composeF4 will skip if the value is blank, but the presence of
// the attribute will prevent ::validate from applying defaults.
if ((has (name) && get (name) != "") ||
if ((has (name) && !get (name).empty()) ||
(name == "due" && Context::getContext ().config.has ("default.due")) ||
(name == "scheduled" && Context::getContext ().config.has ("default.scheduled")) ||
(name == "project" && Context::getContext ().config.has ("default.project")))
@@ -2155,7 +2155,7 @@ void Task::modify (modType type, bool text_required /* = false */)
// Unknown args are accumulated as though they were WORDs.
else
{
if (text != "")
if (!text.empty())
text += ' ';
text += a.attribute ("raw");
}
@@ -2164,7 +2164,7 @@ void Task::modify (modType type, bool text_required /* = false */)
// Task::modType determines what happens to the WORD arguments, if there are
// any.
if (text != "")
if (!text.empty())
{
Lexer::dequote (text);