Skip to content

Commit c3cc578

Browse files
committed
stow the created template on the parser
1 parent 3aa95b8 commit c3cc578

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/inja/parser.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Parser {
2929

3030
Lexer lexer;
3131
TemplateStorage& template_storage;
32+
std::vector<Template> template_stash;
3233
const FunctionStorage& function_storage;
3334

3435
Token tok, peek_tok;
@@ -622,7 +623,7 @@ class Parser {
622623
: config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {}
623624

624625
Template parse(std::string_view input, std::string_view path) {
625-
auto result = Template(static_cast<std::string>(input));
626+
auto& result = template_stash.emplace_back(Template(static_cast<std::string>(input)));
626627
parse_into(result, path);
627628
return result;
628629
}

single_include/inja/inja.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,7 @@ class Parser {
14671467

14681468
Lexer lexer;
14691469
TemplateStorage& template_storage;
1470+
std::vector<Template> template_stash;
14701471
const FunctionStorage& function_storage;
14711472

14721473
Token tok, peek_tok;
@@ -2060,7 +2061,7 @@ class Parser {
20602061
: config(parser_config), lexer(lexer_config), template_storage(template_storage), function_storage(function_storage) {}
20612062

20622063
Template parse(std::string_view input, std::string_view path) {
2063-
auto result = Template(static_cast<std::string>(input));
2064+
auto& result = template_stash.emplace_back(Template(static_cast<std::string>(input)));
20642065
parse_into(result, path);
20652066
return result;
20662067
}
@@ -2153,7 +2154,11 @@ class Renderer : public NodeVisitor {
21532154
if (value->is_string()) {
21542155
std::string val;
21552156
if (config.escape_strings) {
2157+
// get the value as a dump() to properly escape values
21562158
val = value->dump();
2159+
2160+
// strip the leading and trailing " characters that are added by dump()
2161+
// if C++20 is adopted, val.starts_with and val.ends_with would clean this up a bit
21572162
val = val.substr(0,1) == "\"" && val.substr(val.length()-1,1) == "\""
21582163
? val.substr(1, val.length()-2)
21592164
: val;

0 commit comments

Comments
 (0)