Enhanced export command

- Now sanitizes output by replacing ' with " in descriptions.
- Added 'recur' attribute to exported output.
- Removed recurring, deleted and complete tasks from the export.
This commit is contained in:
Paul Beckingham 2009-03-14 13:36:32 -04:00
parent 8ac3978222
commit 5383943fa7
3 changed files with 24 additions and 5 deletions

View file

@ -328,6 +328,11 @@ const std::string T::composeCSV ()
line += value;
line += ",";
value = mAttributes["recur"];
if (value != "")
line += value;
line += ",";
value = mAttributes["end"];
if (value != "")
line += value;
@ -353,7 +358,11 @@ const std::string T::composeCSV ()
line += "'" + value + "'";
line += ",";
line += "'" + mDescription + "'\n";
// Convert single quotes to double quotes, because single quotes are used to
// delimit the values that need it.
std::string clean = mDescription;
std::replace (clean.begin (), clean.end (), '\'', '"');
line += "'" + clean + "'\n";
return line;
}

View file

@ -578,7 +578,7 @@ std::string handleDone (TDB& tdb, T& task, Config& conf)
////////////////////////////////////////////////////////////////////////////////
std::string handleExport (TDB& tdb, T& task, Config& conf)
{
std::stringstream out;
std::stringstream output;
// Use the description as a file name, then clobber the description so the
// file name isn't used for filtering.
@ -597,6 +597,7 @@ std::string handleExport (TDB& tdb, T& task, Config& conf)
<< "'entry',"
<< "'start',"
<< "'due',"
<< "'recur',"
<< "'end',"
<< "'project',"
<< "'priority',"
@ -605,14 +606,22 @@ std::string handleExport (TDB& tdb, T& task, Config& conf)
<< "'description'"
<< "\n";
int count = 0;
std::vector <T> all;
tdb.allT (all);
tdb.allPendingT (all);
filter (all, task);
foreach (t, all)
{
out << t->composeCSV ().c_str ();
if (t->getStatus () != T::recurring &&
t->getStatus () != T::deleted)
{
out << t->composeCSV ().c_str ();
++count;
}
}
out.close ();
output << count << " tasks exported to '" << file << "'" << std::endl;
}
else
throw std::string ("Could not write to export file.");
@ -620,7 +629,7 @@ std::string handleExport (TDB& tdb, T& task, Config& conf)
else
throw std::string ("You must specify a file to write to.");
return out.str ();
return output.str ();
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -187,6 +187,7 @@ static char randomHexDigit ()
{
static char digits[] = "0123456789abcdef";
#ifdef HAVE_RANDOM
// random is better than rand.
return digits[random () % 16];
#else
return digits[rand () % 16];