36 static std::string
render(
const std::string& tpl,
const json& ctx, std::shared_ptr<IFormatter> formatter) {
38 result.reserve(tpl.size());
41 while (pos < tpl.size()) {
42 size_t start = tpl.find(
'{', pos);
44 if (start == std::string::npos) {
45 result.append(tpl, pos, tpl.size() - pos);
49 result.append(tpl, pos, start - pos);
51 size_t end = tpl.find(
'}', start);
52 if (end == std::string::npos) {
53 result.append(tpl, start, tpl.size() - start);
57 std::string raw = tpl.substr(start + 1, end - start - 1);
58 auto ph = parse_placeholder(raw, formatter->style());
62 if (ctx.contains(ph.key)) {
63 const auto& v = ctx[ph.key];
64 value = v.is_string() ? v.get<std::string>() : v.dump();
66 value =
"{" + ph.key +
"}";
69 result.append(formatter->colorize(value, ph.style));