1515 limitations under the License.
1616 */
1717
18- #pragma once
19-
2018#include < string>
21- #include < memory>
2219#include < vector>
2320#include < map>
2421#include < functional>
25- #include < algorithm >
22+ #include < memory >
2623#include < sstream>
24+ #include < algorithm>
2725#include < iostream>
26+ #include < fstream>
27+ #include < regex>
28+ #include < initializer_list>
29+ #include < ctime>
30+ #include < iomanip>
31+ #include < chrono>
2832
2933// External dependency: nlohmann/json
30- #include < nlohmann/json .hpp>
34+ #include " ujson .hpp"
3135
3236#define JINJA_VERSION_MAJOR 0
3337#define JINJA_VERSION_MINOR 0
4246
4347namespace jinja {
4448
45- using json = nlohmann::json;
46- using json = nlohmann::json;
49+ using json = ujson::json;
50+
51+
4752using Argument = std::pair<std::string, json>;
4853using UserFunction = std::function<json(const std::vector<Argument>&)>;
4954
@@ -558,8 +563,6 @@ class Lexer {
558563
559564
560565// --- Helpers ---
561- using json = nlohmann::json;
562-
563566class Context ; // Forward declaration
564567
565568struct Node {
@@ -571,7 +574,12 @@ struct Macro;
571574
572575// Forward declarations
573576static bool is_truthy (const json& val);
574- static const json UNDEFINED = {{" __jinja_undefined__" , true }};
577+ static json undefined_init () {
578+ json j = json::object ();
579+ j[" __jinja_undefined__" ] = true ;
580+ return j;
581+ }
582+ static const json UNDEFINED = undefined_init();
575583
576584inline bool is_undefined (const json& val) {
577585 return val.is_object () && val.contains (" __jinja_undefined__" );
@@ -619,27 +627,25 @@ class Context {
619627 return nullptr ;
620628 }
621629
622- json& get (const std::string& name) {
630+ json get (const std::string& name) {
623631 // Search from top to bottom
624632 for (auto it = scopes.rbegin (); it != scopes.rend (); ++it) {
625633 if (it->contains (name)) {
626634 return (*it)[name];
627635 }
628636 }
629637 JINJA_LOG (" Context: Variable '" << name << " ' not found, returning UNDEFINED" );
630- static json undefined_val = UNDEFINED;
631- return undefined_val;
638+ return UNDEFINED;
632639 }
633640
634- const json& get (const std::string& name) const {
641+ json get (const std::string& name) const {
635642 // Const version
636643 for (auto it = scopes.rbegin (); it != scopes.rend (); ++it) {
637644 if (it->contains (name)) {
638645 return (*it)[name];
639646 }
640647 }
641- static const json undefined_val = UNDEFINED;
642- return undefined_val;
648+ return UNDEFINED;
643649 }
644650
645651 void set (const std::string& name, json val) {
@@ -1284,7 +1290,7 @@ struct SetNode : Node {
12841290 // But Expr::evaluate returns value. We need reference.
12851291 // Context needs to support getting reference.
12861292 if (auto * var = dynamic_cast <VarExpr*>(attr->object .get ())) {
1287- json& obj = context.get (var->name );
1293+ json obj = context.get (var->name );
12881294 if (!obj.is_null ()) {
12891295 obj[attr->name ] = val;
12901296 }
0 commit comments