152{
155
156
157
158
159
160
161 m_env.add_callback(
"empty", 1, [](inja::Arguments &args) {
162 return args.at(0)->get<std::string>().empty();
163 });
164
165
166 m_env.add_callback(
"ltrim", 1, [](inja::Arguments &args) {
167 return util::ltrim(args.at(0)->get<std::string>());
168 });
169
170
171 m_env.add_callback(
"rtrim", 1, [](inja::Arguments &args) {
172 return util::rtrim(args.at(0)->get<std::string>());
173 });
174
175
176 m_env.add_callback(
"trim", 1, [](inja::Arguments &args) {
177 return util::trim(args.at(0)->get<std::string>());
178 });
179
180
181 m_env.add_callback(
"abbrv", 2, [](inja::Arguments &args) {
183 args.at(0)->get<std::string>(), args.at(1)->get<unsigned>());
184 });
185
186 m_env.add_callback(
"replace", 3, [](inja::Arguments &args) {
187 std::string result = args[0]->get<std::string>();
188 std::regex pattern(args[1]->get<std::string>());
189 return std::regex_replace(result, pattern, args[2]->get<std::string>());
190 });
191
192 m_env.add_callback(
"split", 2, [](inja::Arguments &args) {
194 args[0]->get<std::string>(), args[1]->get<std::string>());
195 });
196
197
198
199
200
201
202
203
204
206 inja::json res{};
207 auto element_opt =
model.get_with_namespace(
208 args[0]->get<std::string>(),
config.using_namespace());
209
210 if (element_opt.has_value())
211 res = element_opt.value().context();
212
213 return res;
214 });
215
216
217
218
219
220
222 auto element_opt =
model.get_with_namespace(
223 args[0]->get<std::string>(),
config.using_namespace());
224
225 if (!element_opt.has_value())
227 args[0]->get<std::string>());
228
229 return element_opt.value().alias();
230 });
231
232
233
234
235
236
238 inja::json res{};
239 auto element_opt =
model.get_with_namespace(
240 args[0]->get<std::string>(),
config.using_namespace());
241
242 if (!element_opt.has_value())
244 args[0]->get<std::string>());
245
246 auto comment = element_opt.value().comment();
247
248 if (comment.has_value()) {
249 assert(comment.value().is_object());
250 res = comment.value();
251 }
252
253 return res;
254 });
255}