| 1442 | ANKERL_NANOBENCH(IGNORE_PADDED_POP) |
| 1443 | |
| 1444 | static 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 | |
| 1485 | static 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)); |