Task: Conditional JSON/Task encoding, based on attribute type

This commit is contained in:
Paul Beckingham 2015-11-02 07:54:13 -05:00
parent de4be46cab
commit 3ab2410df3
2 changed files with 14 additions and 9 deletions

View file

@ -402,7 +402,6 @@ std::string json::encode (const std::string& input)
}
////////////////////////////////////////////////////////////////////////////////
// TODO Using a state machine would speed this up.
std::string json::decode (const std::string& input)
{
std::string output;

View file

@ -813,12 +813,16 @@ std::string Task::composeF4 () const
bool first = true;
for (auto it : *this)
{
std::string type = Task::attributes[it.first];
if (type == "")
type = "string";
if (it.second != "")
{
ff4 += (first ? "" : " ")
+ it.first
+ ":\""
+ encode (json::encode (it.second))
+ (type == "string" ? encode (json::encode (it.second)) : it.second)
+ "\"";
first = false;
@ -897,12 +901,13 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
out << "\"tags\":[";
for (auto i = tags.begin (); i != tags.end (); ++i)
int count = 0;
for (auto i : tags)
{
if (i != tags.begin ())
if (count++)
out << ",";
out << "\"" << *i << "\"";
out << "\"" << i << "\"";
}
out << "]";
@ -918,12 +923,13 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
out << "\"depends\":[";
for (auto i = deps.begin (); i != deps.end (); ++i)
int count = 0;
for (auto i : deps)
{
if (i != deps.begin ())
if (count++)
out << ",";
out << "\"" << *i << "\"";
out << "\"" << i << "\"";
}
out << "]";
@ -936,7 +942,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
out << "\""
<< i.first
<< "\":\""
<< json::encode (i.second)
<< (type == "string" ? json::encode (i.second) : i.second)
<< "\"";
++attributes_written;