From 07c9d587e9f5950b95a764d6c5a019a2f746c9ac Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 22 Mar 2016 22:08:11 -0400 Subject: [PATCH] Interval: Proper handling of commas in JSON --- src/Interval.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Interval.cpp b/src/Interval.cpp index ea2b4309..f0986216 100644 --- a/src/Interval.cpp +++ b/src/Interval.cpp @@ -201,13 +201,17 @@ std::string Interval::serialize () const std::string Interval::json () const { std::stringstream out; - out << "{"; + out << '{'; if (_start.toEpoch ()) out << "\"start\":\"" << _start.toISO () << "\""; if (_end.toEpoch ()) - out << ",\"end\":\"" << _end.toISO () << "\""; + { + if (_start.toEpoch ()) + out << ','; + out << "\"end\":\"" << _end.toISO () << "\""; + } if (_tags.size ()) { @@ -215,14 +219,18 @@ std::string Interval::json () const for (auto& tag : _tags) { if (tags[0]) - tags += ","; + tags += ','; tags += "\"" + tag + "\""; } - out << ",\"tags\":[" + if (_start.toEpoch () || + _end.toEpoch ()) + out << ','; + + out << "\"tags\":[" << tags - << "]"; + << ']'; } out << "}";