-
Notifications
You must be signed in to change notification settings - Fork 1
/
openf.cpp
67 lines (44 loc) · 1.08 KB
/
openf.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "openf.hpp"
#include <nlohmann/json.hpp>
using namespace inja;
openf::openf() {}
std::string openf::open_file(std::string filename, json &j)
{
/** open a file with inja **/
Environment env;
Template temp = env.parse_template(filename);
/**env.add_callback("find", 2, [](Arguments& args) {
if ( args.at(0)->get<std::string>().find( args.at(1)->get<std::string>() ) == std::string::npos)
{
return 0;
}
return 1;
});
env.add_callback("f_part", 3, [](Arguments& args) {
std::string send = args.at(0)->get<std::string>();
std::size_t found;
std::string ui = args.at(1)->get<std::string>();
for (int i {0}; i < args.at(2)->get<int>(); i++)
{
found = send.find(ui);
if (found != std::string::npos and found+1 < send.size())
{
send.erase(0, found+1);
}
else
{
return "";
}
}
found = send.find(ui);
if (found != std::string::npos)
{
send.erase(found, send.size() - found);
return send.c_str();
}
return send.c_str();
});**/
std::string result = env.render(temp, j);
return result;
}
openf::~openf() {}