mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Task: Conditional JSON/Task encoding, based on attribute type
This commit is contained in:
parent
de4be46cab
commit
3ab2410df3
2 changed files with 14 additions and 9 deletions
|
@ -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 json::decode (const std::string& input)
|
||||||
{
|
{
|
||||||
std::string output;
|
std::string output;
|
||||||
|
|
22
src/Task.cpp
22
src/Task.cpp
|
@ -813,12 +813,16 @@ std::string Task::composeF4 () const
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (auto it : *this)
|
for (auto it : *this)
|
||||||
{
|
{
|
||||||
|
std::string type = Task::attributes[it.first];
|
||||||
|
if (type == "")
|
||||||
|
type = "string";
|
||||||
|
|
||||||
if (it.second != "")
|
if (it.second != "")
|
||||||
{
|
{
|
||||||
ff4 += (first ? "" : " ")
|
ff4 += (first ? "" : " ")
|
||||||
+ it.first
|
+ it.first
|
||||||
+ ":\""
|
+ ":\""
|
||||||
+ encode (json::encode (it.second))
|
+ (type == "string" ? encode (json::encode (it.second)) : it.second)
|
||||||
+ "\"";
|
+ "\"";
|
||||||
|
|
||||||
first = false;
|
first = false;
|
||||||
|
@ -897,12 +901,13 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
|
||||||
|
|
||||||
out << "\"tags\":[";
|
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 << ",";
|
||||||
|
|
||||||
out << "\"" << *i << "\"";
|
out << "\"" << i << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "]";
|
out << "]";
|
||||||
|
@ -918,12 +923,13 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
|
||||||
|
|
||||||
out << "\"depends\":[";
|
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 << ",";
|
||||||
|
|
||||||
out << "\"" << *i << "\"";
|
out << "\"" << i << "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "]";
|
out << "]";
|
||||||
|
@ -936,7 +942,7 @@ std::string Task::composeJSON (bool decorate /*= false*/) const
|
||||||
out << "\""
|
out << "\""
|
||||||
<< i.first
|
<< i.first
|
||||||
<< "\":\""
|
<< "\":\""
|
||||||
<< json::encode (i.second)
|
<< (type == "string" ? json::encode (i.second) : i.second)
|
||||||
<< "\"";
|
<< "\"";
|
||||||
|
|
||||||
++attributes_written;
|
++attributes_written;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue