From 3ab2410df3bb419d066756503940c52b9693d808 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 2 Nov 2015 07:54:13 -0500 Subject: [PATCH] Task: Conditional JSON/Task encoding, based on attribute type --- src/JSON.cpp | 1 - src/Task.cpp | 22 ++++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/JSON.cpp b/src/JSON.cpp index e85324739..2db944f88 100644 --- a/src/JSON.cpp +++ b/src/JSON.cpp @@ -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; diff --git a/src/Task.cpp b/src/Task.cpp index b087afd8f..ca785d202 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -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;