MCPcopy Create free account
hub / github.com/ElementsProject/elements / parseMustacheTemplate

Function parseMustacheTemplate

src/bench/nanobench.h:1444–1483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1442ANKERL_NANOBENCH(IGNORE_PADDED_POP)
1443
1444static std::vector<Node> parseMustacheTemplate(char const** tpl) {
1445 std::vector<Node> nodes;
1446
1447 while (true) {
1448 auto begin = std::strstr(*tpl, "{{");
1449 auto end = begin;
1450 if (begin != nullptr) {
1451 begin += 2;
1452 end = std::strstr(begin, "}}");
1453 }
1454
1455 if (begin == nullptr || end == nullptr) {
1456 // nothing found, finish node
1457 nodes.emplace_back(Node{*tpl, *tpl + std::strlen(*tpl), std::vector<Node>{}, Node::Type::content});
1458 return nodes;
1459 }
1460
1461 nodes.emplace_back(Node{*tpl, begin - 2, std::vector<Node>{}, Node::Type::content});
1462
1463 // we found a tag
1464 *tpl = end + 2;
1465 switch (*begin) {
1466 case '/':
1467 // finished! bail out
1468 return nodes;
1469
1470 case '#':
1471 nodes.emplace_back(Node{begin + 1, end, parseMustacheTemplate(tpl), Node::Type::section});
1472 break;
1473
1474 case '^':
1475 nodes.emplace_back(Node{begin + 1, end, parseMustacheTemplate(tpl), Node::Type::inverted_section});
1476 break;
1477
1478 default:
1479 nodes.emplace_back(Node{begin, end, std::vector<Node>{}, Node::Type::tag});
1480 break;
1481 }
1482 }
1483}
1484
1485static bool generateFirstLast(Node const& n, size_t idx, size_t size, std::ostream& out) {
1486 ANKERL_NANOBENCH_LOG("n.type=" << static_cast<int>(n.type));

Callers 1

renderFunction · 0.85

Calls 1

emplace_backMethod · 0.80

Tested by

no test coverage detected