Add curly braces

This commit is contained in:
Thomas Lauf 2019-02-26 22:20:06 +01:00
parent 44ed56ad38
commit 04adb50480
3 changed files with 26 additions and 0 deletions

View file

@ -56,7 +56,9 @@ std::vector <std::string> Database::files () const
{
std::vector <std::string> all;
for (auto& file : _files)
{
all.push_back (file.name ());
}
return all;
}
@ -75,7 +77,9 @@ std::string Database::lastLine ()
{
auto line = ri->lastLine ();
if (! line.empty ())
{
return line;
}
}
return "";
@ -272,7 +276,9 @@ std::string Database::dump () const
std::stringstream out;
out << "Database\n";
for (auto& df : _files)
{
out << df.dump ();
}
return out.str ();
}
@ -292,8 +298,12 @@ unsigned int Database::getDatafile (int year, int month)
// If the datafile is already initialized, return.
for (unsigned int i = 0; i < _files.size (); ++i)
{
if (_files[i].name () == basename)
{
return i;
}
}
// Create the Datafile.
Datafile df;
@ -325,7 +335,9 @@ std::vector <Range> Database::segmentRange (const Range& range)
auto end = range.end;
if (end.toEpoch () == 0)
{
end = Datetime ();
}
auto end_y = end.year ();
auto end_m = end.month ();
@ -374,7 +386,9 @@ void Database::initializeTagDatabase ()
auto* value = (json::object*) pair.second;
auto iter = value->_data.find ("count");
if (iter == value->_data.end ())
{
throw format ("Failed to find \"count\" member for tag \"{1}\" in tags database. Database corrupted?", key);
}
auto number = static_cast<json::number *> (iter->second);
_tagInfoDatabase.add (key, TagInfo {(unsigned int) number->_dvalue});
}

View file

@ -43,7 +43,9 @@ int CmdJoin (
// Only 2 IDs allowed in a join.
if (ids.size () != 2)
{
throw std::string ("Two IDs must be specified. See 'timew help join'.");
}
// Load the data.
// Note: There is no filter.
@ -87,7 +89,9 @@ int CmdJoin (
database.endTransaction ();
if (rules.getBoolean ("verbose"))
{
std::cout << "Joined @" << first_id << " and @" << second_id << '\n';
}
return 0;
}

View file

@ -55,7 +55,9 @@ std::string escape (const std::string& input, int c)
std::string quoteIfNeeded (const std::string& input)
{
if (input[0] == '"' || input[0] == '\'')
{
return input;
}
auto quote = input.find ('"');
auto space = input.find (' ');
@ -64,13 +66,19 @@ std::string quoteIfNeeded (const std::string& input)
if (quote == std::string::npos &&
space == std::string::npos &&
op == std::string::npos)
{
return input;
}
std::string output;
if (quote != std::string::npos)
{
output = escape (input, '"');
}
else
{
output = input;
}
return std::string ("\"") + output + "\"";
}