helper: Added jsonFromIntervals

This commit is contained in:
Paul Beckingham 2016-04-09 09:44:46 -04:00
parent 4b1bf763d5
commit 57b45f9c73
2 changed files with 34 additions and 0 deletions

View file

@ -215,3 +215,36 @@ bool intervalMatchesFilter (const Interval& interval, const Filter& filter)
}
////////////////////////////////////////////////////////////////////////////////
// Compose a JSON document of intervals. In the trivial case:
// [
// ]
//
// In the non-trivial case:
// [
// {...},
// {...}
// ]
//
std::string jsonFromIntervals (const std::vector <Interval>& intervals)
{
std::stringstream out;
out << "[\n";
int counter = 0;
for (auto& interval : intervals)
{
if (counter)
out << ",\n";
out << interval.json ();
++counter;
}
if (counter)
out << "\n";
out << "]\n";
return out.str ();
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -51,6 +51,7 @@ Filter createFilterFromCLI (const CLI&);
Timeline createTimelineFromData (const Rules&, Database&, const Filter&);
Interval getLatestInterval (Timeline&, Database&, const Filter&);
bool intervalMatchesFilter (const Interval&, const Filter&);
std::string jsonFromIntervals (const std::vector <Interval>&);
// utiŀ.cpp
std::string osName ();