File tree Expand file tree Collapse file tree 4 files changed +15
-9
lines changed Expand file tree Collapse file tree 4 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -74,9 +74,9 @@ class BlockNode : public AstNode {
74
74
75
75
class TextNode : public AstNode {
76
76
public:
77
- std::string content ;
77
+ size_t length ;
78
78
79
- explicit TextNode (nonstd::string_view content , size_t pos ): AstNode(pos), content(content ) { }
79
+ explicit TextNode (size_t pos , size_t length ): AstNode(pos), length(length ) { }
80
80
81
81
void accept (NodeVisitor& v) const {
82
82
v.visit (*this );
@@ -108,14 +108,19 @@ class JsonNode : public ExpressionNode {
108
108
std::string name;
109
109
std::string ptr {" " };
110
110
111
- explicit JsonNode (nonstd::string_view ptr_name, size_t pos) : ExpressionNode(pos), name( ptr_name) {
112
- // Convert dot notation to json pointer notation
111
+ static std::string convert_dot_to_json_ptr (nonstd::string_view ptr_name) {
112
+ std::string result;
113
113
do {
114
114
nonstd::string_view part;
115
115
std::tie (part, ptr_name) = string_view::split (ptr_name, ' .' );
116
- ptr .push_back (' /' );
117
- ptr .append (part.begin (), part.end ());
116
+ result .push_back (' /' );
117
+ result .append (part.begin (), part.end ());
118
118
} while (!ptr_name.empty ());
119
+ return result;
120
+ }
121
+
122
+ explicit JsonNode (nonstd::string_view ptr_name, size_t pos) : ExpressionNode(pos), name(ptr_name) {
123
+ ptr = convert_dot_to_json_ptr (ptr_name);
119
124
}
120
125
121
126
void accept (NodeVisitor& v) const {
Original file line number Diff line number Diff line change @@ -471,7 +471,7 @@ class Parser {
471
471
}
472
472
} return ;
473
473
case Token::Kind::Text: {
474
- current_block->nodes .emplace_back (std::make_shared<TextNode>(tok.text , tok. text . data () - tmpl.content .c_str ()));
474
+ current_block->nodes .emplace_back (std::make_shared<TextNode>(tok.text . data () - tmpl.content .c_str (), tok. text . size ()));
475
475
} break ;
476
476
case Token::Kind::StatementOpen: {
477
477
get_next_token ();
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ class Renderer : public NodeVisitor {
147
147
}
148
148
149
149
void visit (const TextNode& node) {
150
- * output_stream << node.content ;
150
+ output_stream-> write (current_template-> content . c_str () + node.pos , node. length ) ;
151
151
}
152
152
153
153
void visit (const ExpressionNode&) { }
@@ -344,7 +344,7 @@ class Renderer : public NodeVisitor {
344
344
} break ;
345
345
case Op::Exists: {
346
346
auto &&name = get_arguments<1 >(node)[0 ]->get_ref <const std::string &>();
347
- result_ptr = std::make_shared<json>(json_input->contains (json::json_pointer (JsonNode (name, 0 ). ptr )));
347
+ result_ptr = std::make_shared<json>(json_input->contains (json::json_pointer (JsonNode::convert_dot_to_json_ptr (name) )));
348
348
json_tmp_stack.push_back (result_ptr);
349
349
json_eval_stack.push (result_ptr.get ());
350
350
} break ;
Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ TEST_CASE("functions") {
74
74
SUBCASE (" at" ) {
75
75
CHECK (env.render (" {{ at(names, 0) }}" , data) == " Jeff" );
76
76
CHECK (env.render (" {{ at(names, i) }}" , data) == " Seb" );
77
+ // CHECK(env.render("{{ at(names, 45) }}", data) == "Jeff");
77
78
}
78
79
79
80
SUBCASE (" first" ) {
You can’t perform that action at this time.
0 commit comments