mirror of
https://github.com/pantor/inja.git
synced 2026-04-15 12:38:53 +00:00
add first and last function
This commit is contained in:
12
src/inja.hpp
12
src/inja.hpp
@@ -243,6 +243,8 @@ struct Parsed {
|
||||
Lower,
|
||||
Range,
|
||||
Length,
|
||||
First,
|
||||
Last,
|
||||
Round,
|
||||
DivisibleBy,
|
||||
Odd,
|
||||
@@ -356,6 +358,14 @@ public:
|
||||
const std::vector<json> list = eval_expression<std::vector<json>>(element.args[0], data);
|
||||
return list.size();
|
||||
}
|
||||
case Parsed::Function::First: {
|
||||
const std::vector<json> list = eval_expression<std::vector<json>>(element.args[0], data);
|
||||
return list.front();
|
||||
}
|
||||
case Parsed::Function::Last: {
|
||||
const std::vector<json> list = eval_expression<std::vector<json>>(element.args[0], data);
|
||||
return list.back();
|
||||
}
|
||||
case Parsed::Function::Round: {
|
||||
const double number = eval_expression<double>(element.args[0], data);
|
||||
const int precision = eval_expression<int>(element.args[1], data);
|
||||
@@ -548,6 +558,8 @@ public:
|
||||
{Parsed::Function::Lower, function_regex("lower", 1)},
|
||||
{Parsed::Function::Range, function_regex("range", 1)},
|
||||
{Parsed::Function::Length, function_regex("length", 1)},
|
||||
{Parsed::Function::First, function_regex("first", 1)},
|
||||
{Parsed::Function::Last, function_regex("last", 1)},
|
||||
{Parsed::Function::Round, function_regex("round", 2)},
|
||||
{Parsed::Function::DivisibleBy, function_regex("divisibleBy", 2)},
|
||||
{Parsed::Function::Odd, function_regex("odd", 1)},
|
||||
|
||||
Reference in New Issue
Block a user