#include #include #include "hexxer.hpp" template auto hexify (const R& range) { std::stringstream ss; for (auto& x : range) { ss << hexxer::encodeFirst(x) << hexxer::encodeSecond(x); } return ss.str(); } auto jsonify (const std::string& v) { return "\"" + v + "\""; } template std::enable_if_t::value, std::string> jsonify (const R& r) { return jsonify(hexify(r)); } auto jsonp (const std::string& k, const std::string& v) { std::stringstream ss; ss << "\"" << k << "\": " << v; return ss.str(); } auto jsonify (const bool v) { return v ? "true" : "false"; } template auto jsonify_csv (const Range r, F f) { std::stringstream ss; size_t i = 0; if (L != ' ') ss << L; for (const auto& x : r) { const auto fx = f(x); if (fx.empty()) continue; if (i++ > 0) ss << ','; ss << fx; } if (R != ' ') ss << R; return ss.str(); } auto json_identity (const std::string& s) { return s; } template , typename F = decltype(json_identity)> auto jsonifyO (const R& r, F f = json_identity) { return jsonify_csv<'{', '}'>(r, f); } template , typename F = decltype(json_identity)> auto jsonifyA (const R& r, F f = json_identity) { return jsonify_csv<'[', ']'>(r, f); }