Interval: Proper handling of commas in JSON

This commit is contained in:
Paul Beckingham 2016-03-22 22:08:11 -04:00
parent 71b2320def
commit 07c9d587e9

View file

@ -201,13 +201,17 @@ std::string Interval::serialize () const
std::string Interval::json () const std::string Interval::json () const
{ {
std::stringstream out; std::stringstream out;
out << "{"; out << '{';
if (_start.toEpoch ()) if (_start.toEpoch ())
out << "\"start\":\"" << _start.toISO () << "\""; out << "\"start\":\"" << _start.toISO () << "\"";
if (_end.toEpoch ()) if (_end.toEpoch ())
out << ",\"end\":\"" << _end.toISO () << "\""; {
if (_start.toEpoch ())
out << ',';
out << "\"end\":\"" << _end.toISO () << "\"";
}
if (_tags.size ()) if (_tags.size ())
{ {
@ -215,14 +219,18 @@ std::string Interval::json () const
for (auto& tag : _tags) for (auto& tag : _tags)
{ {
if (tags[0]) if (tags[0])
tags += ","; tags += ',';
tags += "\"" + tag + "\""; tags += "\"" + tag + "\"";
} }
out << ",\"tags\":[" if (_start.toEpoch () ||
_end.toEpoch ())
out << ',';
out << "\"tags\":["
<< tags << tags
<< "]"; << ']';
} }
out << "}"; out << "}";