mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Use the empty method to check for emptiness instead of comparing to an empty object
This commit is contained in:
parent
b5acfed98f
commit
2c5812f7a3
17 changed files with 51 additions and 50 deletions
|
@ -327,7 +327,7 @@ bool CLI::canonicalize (
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string CLI::getBinary () const
|
||||
{
|
||||
if (_args.size ())
|
||||
if (! _args.empty ())
|
||||
return _args[0].attribute ("raw");
|
||||
|
||||
return "";
|
||||
|
@ -366,7 +366,7 @@ std::string CLI::dump (const std::string& title) const
|
|||
|
||||
out << '\n';
|
||||
|
||||
if (_args.size ())
|
||||
if (! _args.empty ())
|
||||
{
|
||||
out << " _args\n";
|
||||
for (auto& a : _args)
|
||||
|
|
|
@ -61,14 +61,14 @@ std::vector <std::string> Database::files () const
|
|||
// Walk backwards through the files until an interval is found.
|
||||
std::string Database::lastLine ()
|
||||
{
|
||||
if (! _files.size ())
|
||||
if (_files.empty ())
|
||||
initializeDatafiles ();
|
||||
|
||||
std::vector <Datafile>::reverse_iterator ri;
|
||||
for (ri = _files.rbegin (); ri != _files.rend (); ri++)
|
||||
{
|
||||
auto line = ri->lastLine ();
|
||||
if (line != "")
|
||||
if (! line.empty ())
|
||||
return line;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ std::string Database::lastLine ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::vector <std::string> Database::allLines ()
|
||||
{
|
||||
if (! _files.size ())
|
||||
if (_files.empty ())
|
||||
initializeDatafiles ();
|
||||
|
||||
std::vector <std::string> all;
|
||||
|
|
|
@ -44,7 +44,7 @@ void Interval::initialize (const std::string& line)
|
|||
tokens.push_back (Lexer::dequote (token));
|
||||
|
||||
// Minimal requirement 'inc'.
|
||||
if (tokens.size () &&
|
||||
if (!tokens.empty () &&
|
||||
tokens[0] == "inc")
|
||||
{
|
||||
unsigned int offset = 0;
|
||||
|
@ -86,7 +86,7 @@ bool Interval::empty () const
|
|||
{
|
||||
return range.start.toEpoch () == 0 &&
|
||||
range.end.toEpoch () == 0 &&
|
||||
_tags.size () == 0;
|
||||
_tags.empty ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -126,7 +126,7 @@ std::string Interval::serialize () const
|
|||
if (range.end.toEpoch ())
|
||||
out << " - " << range.end.toISO ();
|
||||
|
||||
if (_tags.size ())
|
||||
if (! _tags.empty ())
|
||||
{
|
||||
out << " #";
|
||||
for (auto& tag : _tags)
|
||||
|
@ -152,7 +152,7 @@ std::string Interval::json () const
|
|||
out << "\"end\":\"" << range.end.toISO () << "\"";
|
||||
}
|
||||
|
||||
if (_tags.size ())
|
||||
if (! _tags.empty ())
|
||||
{
|
||||
std::string tags;
|
||||
for (auto& tag : _tags)
|
||||
|
@ -192,7 +192,7 @@ std::string Interval::dump () const
|
|||
if (range.end.toEpoch ())
|
||||
out << " - " << range.end.toISOLocalExtended ();
|
||||
|
||||
if (_tags.size ())
|
||||
if (! _tags.empty ())
|
||||
{
|
||||
out << " #";
|
||||
for (auto& tag : _tags)
|
||||
|
|
|
@ -223,7 +223,7 @@ std::vector <std::string> Rules::all (const std::string& stem) const
|
|||
{
|
||||
std::vector <std::string> items;
|
||||
for (const auto& it : _settings)
|
||||
if (stem == "" || it.first.find (stem) == 0)
|
||||
if (stem.empty () || it.first.find (stem) == 0)
|
||||
items.push_back (it.first);
|
||||
|
||||
return items;
|
||||
|
@ -274,7 +274,7 @@ void Rules::parse (const std::string& input, int nest /* = 1 */)
|
|||
auto indent = line.find_first_not_of (' ');
|
||||
|
||||
auto tokens = Lexer::tokenize (line);
|
||||
if (tokens.size ())
|
||||
if (! tokens.empty ())
|
||||
{
|
||||
if (inRule)
|
||||
{
|
||||
|
@ -302,7 +302,7 @@ void Rules::parse (const std::string& input, int nest /* = 1 */)
|
|||
//
|
||||
if (firstWord == "define")
|
||||
{
|
||||
if (ruleDef != "")
|
||||
if (! ruleDef.empty ())
|
||||
{
|
||||
parseRule (ruleDef);
|
||||
ruleDef = "";
|
||||
|
@ -357,7 +357,7 @@ void Rules::parse (const std::string& input, int nest /* = 1 */)
|
|||
}
|
||||
}
|
||||
|
||||
if (ruleDef != "")
|
||||
if (! ruleDef.empty ())
|
||||
parseRule (ruleDef);
|
||||
}
|
||||
|
||||
|
@ -411,7 +411,7 @@ void Rules::parseRuleSettings (
|
|||
// If indent decreased.
|
||||
else if (indent < indents.back ())
|
||||
{
|
||||
while (indents.size () && indent != indents.back ())
|
||||
while (!indents.empty () && indent != indents.back ())
|
||||
{
|
||||
indents.pop_back ();
|
||||
hierarchy.pop_back ();
|
||||
|
@ -423,7 +423,7 @@ void Rules::parseRuleSettings (
|
|||
}
|
||||
|
||||
// Descend.
|
||||
if (group != "")
|
||||
if (! group.empty ())
|
||||
hierarchy.push_back (group);
|
||||
|
||||
// Settings.
|
||||
|
|
|
@ -241,7 +241,7 @@ static void determineHourRange (
|
|||
last_hour = 23;
|
||||
|
||||
// If there is no data, show the whole day.
|
||||
if (tracked.size ())
|
||||
if (! tracked.empty ())
|
||||
{
|
||||
// Get the extreme time range for the filtered data.
|
||||
first_hour = 23;
|
||||
|
@ -562,7 +562,7 @@ static void renderInterval (
|
|||
|
||||
for (auto& tag : track.tags ())
|
||||
{
|
||||
if (label != "")
|
||||
if (! label.empty ())
|
||||
label += ' ';
|
||||
|
||||
label += tag;
|
||||
|
|
|
@ -126,8 +126,7 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
|
|||
value)))
|
||||
{
|
||||
// Add blank line required by rules.
|
||||
if (lines.size () &&
|
||||
lines.back () != "")
|
||||
if (lines.empty () || lines.back ().empty ())
|
||||
lines.push_back ("");
|
||||
|
||||
// Add new line.
|
||||
|
@ -150,8 +149,7 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
|
|||
// new leaf/value properly. But that's non-trivial.
|
||||
|
||||
// Add blank line required by rules.
|
||||
if (lines.size () &&
|
||||
lines.back () != "")
|
||||
if (lines.empty () || lines.back ().empty ())
|
||||
lines.push_back ("");
|
||||
|
||||
// Add new line.
|
||||
|
@ -272,7 +270,7 @@ int CmdConfig (
|
|||
// task config name value # set name to value
|
||||
// task config name "" # set name to blank
|
||||
// task config name # remove name
|
||||
if (words.size ())
|
||||
if (! words.empty ())
|
||||
{
|
||||
bool confirmation = rules.getBoolean ("confirmation");
|
||||
std::string name = words[0];
|
||||
|
@ -290,7 +288,7 @@ int CmdConfig (
|
|||
}
|
||||
}
|
||||
|
||||
if (name != "")
|
||||
if (! name.empty ())
|
||||
{
|
||||
bool change = false;
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ int CmdDiagnostics (
|
|||
<< " Location: " << describeFile (extDir) << '\n';
|
||||
|
||||
auto exts = extensions.all ();
|
||||
if (exts.size ())
|
||||
if (! exts.empty ())
|
||||
{
|
||||
unsigned int longest = 0;
|
||||
for (auto& e : exts)
|
||||
|
|
|
@ -67,7 +67,7 @@ int CmdHelpUsage (const Extensions& extensions)
|
|||
<< " timew week [<interval>] [<tag> ...]\n"
|
||||
<< '\n';
|
||||
|
||||
if (extensions.all ().size ())
|
||||
if (!extensions.all ().empty ())
|
||||
{
|
||||
std::cout << "Extensions (extensions do not provide help):\n";
|
||||
|
||||
|
@ -120,7 +120,8 @@ int CmdHelp (
|
|||
const Extensions& extensions)
|
||||
{
|
||||
auto words = cli.getWords ();
|
||||
if (words.size ())
|
||||
|
||||
if (! words.empty ())
|
||||
{
|
||||
// Ruler 1 2 3 4 5 6 7 8
|
||||
// 12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
|
|
@ -47,7 +47,7 @@ static std::string findExtension (
|
|||
std::vector <std::string> matches;
|
||||
autoComplete (partial, options, matches);
|
||||
|
||||
if (matches.size () == 0)
|
||||
if (matches.empty ())
|
||||
throw format ("The report '{1}' is not recognized.", partial);
|
||||
|
||||
if (matches.size () > 1)
|
||||
|
@ -75,7 +75,7 @@ int CmdReport (
|
|||
if (arg.hasTag ("EXT"))
|
||||
script = findExtension (extensions, arg.attribute ("canonical"));
|
||||
|
||||
if (script == "")
|
||||
if (script.empty ())
|
||||
throw std::string ("Specify which report to run.");
|
||||
|
||||
// Compose Header info.
|
||||
|
|
|
@ -84,7 +84,7 @@ int CmdStop (
|
|||
|
||||
// If tags are specified, but are not a full set of tags, remove them
|
||||
// before closing the interval.
|
||||
if (filter.tags ().size () &&
|
||||
if (! filter.tags ().empty () &&
|
||||
setIntersect (filter.tags (), latest.tags ()).size () != latest.tags ().size ())
|
||||
{
|
||||
for (auto& tag : filter.tags ())
|
||||
|
@ -95,7 +95,7 @@ int CmdStop (
|
|||
}
|
||||
|
||||
// Open a new interval with remaining tags, if any.
|
||||
if (filter.tags ().size () &&
|
||||
if (! filter.tags ().empty () &&
|
||||
modified.tags ().size () != latest.tags ().size ())
|
||||
{
|
||||
modified.range.start = modified.range.end;
|
||||
|
|
|
@ -65,7 +65,7 @@ int CmdSummary (
|
|||
std::cout << " - " << filter.range.end.toISOLocalExtended ();
|
||||
}
|
||||
|
||||
if (filter.tags ().size ())
|
||||
if (! filter.tags ().empty ())
|
||||
{
|
||||
std::cout << " tagged with " << joinQuotedIfNeeded (", ", filter.tags ());
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ int CmdTags (
|
|||
tags.insert (tag);
|
||||
|
||||
// Shows all tags.
|
||||
if (tags.size ())
|
||||
if (! tags.empty ())
|
||||
{
|
||||
Table t;
|
||||
t.width (1024);
|
||||
|
|
18
src/data.cpp
18
src/data.cpp
|
@ -81,16 +81,16 @@ Interval getFilter (const CLI& cli)
|
|||
}
|
||||
else if (arg._lextype == Lexer::Type::date)
|
||||
{
|
||||
if (start == "")
|
||||
if (start.empty ())
|
||||
start = raw;
|
||||
else if (end == "")
|
||||
else if (end.empty ())
|
||||
end = raw;
|
||||
|
||||
args.push_back ("<date>");
|
||||
}
|
||||
else if (arg._lextype == Lexer::Type::duration)
|
||||
{
|
||||
if (duration == "")
|
||||
if (duration.empty ())
|
||||
duration = raw;
|
||||
|
||||
args.push_back ("<duration>");
|
||||
|
@ -208,7 +208,7 @@ Interval getFilter (const CLI& cli)
|
|||
}
|
||||
|
||||
// Unrecognized date range construct.
|
||||
else if (args.size ())
|
||||
else if (! args.empty ())
|
||||
{
|
||||
throw std::string ("Unrecognized date range: '") + join (" ", args) + "'.";
|
||||
}
|
||||
|
@ -291,9 +291,9 @@ std::vector <Range> getAllExclusions (
|
|||
|
||||
// daysOff are combined with existing holidays.
|
||||
results = addRanges (range, results, daysOff);
|
||||
if (daysOn.size ())
|
||||
if (! daysOn.empty ())
|
||||
debug (format ("Found {1} additional working days", daysOn.size ()));
|
||||
if (daysOff.size ())
|
||||
if (! daysOff.empty ())
|
||||
debug (format ("Found {1} additional non-working days", daysOff.size ()));
|
||||
|
||||
// daysOn are subtracted from the existing holidays.
|
||||
|
@ -606,7 +606,7 @@ std::vector <Interval> getTracked (
|
|||
if (outer.total ())
|
||||
filter.range = outer;
|
||||
|
||||
if (inclusions.size() > 0) {
|
||||
if (! inclusions.empty ()) {
|
||||
auto latest = inclusions.back();
|
||||
if (latest.range.is_open()) {;
|
||||
filter.range.end = 0;
|
||||
|
@ -616,7 +616,7 @@ std::vector <Interval> getTracked (
|
|||
|
||||
std::vector <Interval> intervals = inclusions;
|
||||
|
||||
if (intervals.size () > 0)
|
||||
if (! intervals.empty ())
|
||||
{
|
||||
auto latest = inclusions.back ();
|
||||
|
||||
|
@ -682,7 +682,7 @@ Interval getLatestInterval (Database& database)
|
|||
}
|
||||
|
||||
auto lastLine = database.lastLine ();
|
||||
if (lastLine != "")
|
||||
if (! lastLine.empty ())
|
||||
i.initialize (lastLine);
|
||||
|
||||
return i;
|
||||
|
|
|
@ -47,7 +47,7 @@ Color intervalColor (
|
|||
std::string first_tag;
|
||||
for (auto& tag : interval.tags ())
|
||||
{
|
||||
if (first_tag == "")
|
||||
if (first_tag.empty ())
|
||||
first_tag = tag;
|
||||
|
||||
std::string name = std::string ("tags.") + tag + ".color";
|
||||
|
@ -58,7 +58,7 @@ Color intervalColor (
|
|||
if (c.nontrivial ())
|
||||
return c;
|
||||
|
||||
if (interval.tags ().size ())
|
||||
if (! interval.tags ().empty ())
|
||||
return tag_colors[first_tag];
|
||||
|
||||
return c;
|
||||
|
@ -106,7 +106,7 @@ std::string intervalSummarize (
|
|||
std::string tags;
|
||||
for (auto& tag : interval.tags ())
|
||||
{
|
||||
if (tags != "")
|
||||
if (! tags.empty ())
|
||||
tags += " ";
|
||||
|
||||
tags += tagColor (rules, tag).colorize (quoteIfNeeded (tag));
|
||||
|
@ -345,7 +345,8 @@ Palette createPalette (const Rules& rules)
|
|||
{
|
||||
Palette p;
|
||||
auto colors = rules.all ("theme.palette.color");
|
||||
if (colors.size ())
|
||||
|
||||
if (! colors.empty ())
|
||||
{
|
||||
p.clear ();
|
||||
for (auto& c : colors)
|
||||
|
|
|
@ -249,7 +249,8 @@ int dispatchCommand (
|
|||
|
||||
// Dispatch to the right command function.
|
||||
std::string command = cli.getCommand ();
|
||||
if (command != "")
|
||||
|
||||
if (! command.empty ())
|
||||
{
|
||||
// These signatures are expected to be all different, therefore no
|
||||
// command to fn mapping.
|
||||
|
@ -291,7 +292,7 @@ int dispatchCommand (
|
|||
{
|
||||
auto words = cli.getWords ();
|
||||
|
||||
if (words.size () > 0)
|
||||
if (! words.empty ())
|
||||
{
|
||||
throw format ("'{1}' is not a timew command. See 'timew help'.", words[0]);
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ int main (int, char**)
|
|||
// no results.
|
||||
exclusions = {{Datetime ("20151201T000000"), Datetime ("20160201T000000")}};
|
||||
subtracted = subtractRanges ({limit}, exclusions);
|
||||
t.ok (subtracted.size () == 0, "subtractRanges: all_day - 2 overlapping months = 0 ranges");
|
||||
t.ok (subtracted.empty (), "subtractRanges: all_day - 2 overlapping months = 0 ranges");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ int main (int, char**)
|
|||
// std::set <std::string> tags () const;
|
||||
// void tag (const std::string&);
|
||||
Interval i2;
|
||||
t.ok (i2.tags () == std::set <std::string> {}, "Interval(tag=) -> {}");
|
||||
t.ok (i2.tags ().empty (), "Interval(tag=) -> {}");
|
||||
i2.tag ("foo");
|
||||
t.ok (i2.tags () == std::set <std::string> {"foo"}, "Interval(tag=foo) -> {foo}");
|
||||
i2.tag ("foo"); // Duplicate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue