mirror of
https://github.com/pantor/inja.git
synced 2026-08-20 22:33:18 +00:00
* fix: return empty string from capitalize on empty input (#337) Signed-off-by: sofiamartincraft <sofiamartincraft@users.noreply.github.com> * fix: return empty string from capitalize on empty input (#337) Signed-off-by: sofiamartincraft <sofiamartincraft@users.noreply.github.com> * fix: return empty string from capitalize on empty input (#337) Signed-off-by: sofiamartincraft <sofiamartincraft@users.noreply.github.com> --------- Signed-off-by: sofiamartincraft <sofiamartincraft@users.noreply.github.com> Co-authored-by: sofiamartincraft <sofiamartincraft@users.noreply.github.com>
This commit is contained in:
co-authored by
sofiamartincraft
parent
94289188ea
commit
fb1437ba59
@@ -344,8 +344,10 @@ class Renderer : public NodeVisitor {
|
||||
} break;
|
||||
case Op::Capitalize: {
|
||||
auto result = get_arguments<1>(node)[0]->get<json::string_t>();
|
||||
result[0] = static_cast<char>(::toupper(result[0]));
|
||||
std::transform(result.begin() + 1, result.end(), result.begin() + 1, [](char c) { return static_cast<char>(::tolower(c)); });
|
||||
if (!result.empty()) {
|
||||
result[0] = static_cast<char>(::toupper(result[0]));
|
||||
std::transform(result.begin() + 1, result.end(), result.begin() + 1, [](char c) { return static_cast<char>(::tolower(c)); });
|
||||
}
|
||||
make_result(std::move(result));
|
||||
} break;
|
||||
case Op::Default: {
|
||||
|
||||
@@ -2496,8 +2496,10 @@ class Renderer : public NodeVisitor {
|
||||
} break;
|
||||
case Op::Capitalize: {
|
||||
auto result = get_arguments<1>(node)[0]->get<json::string_t>();
|
||||
result[0] = static_cast<char>(::toupper(result[0]));
|
||||
std::transform(result.begin() + 1, result.end(), result.begin() + 1, [](char c) { return static_cast<char>(::tolower(c)); });
|
||||
if (!result.empty()) {
|
||||
result[0] = static_cast<char>(::toupper(result[0]));
|
||||
std::transform(result.begin() + 1, result.end(), result.begin() + 1, [](char c) { return static_cast<char>(::tolower(c)); });
|
||||
}
|
||||
make_result(std::move(result));
|
||||
} break;
|
||||
case Op::Default: {
|
||||
|
||||
@@ -65,6 +65,7 @@ TEST_CASE("functions") {
|
||||
SUBCASE("capitalize") {
|
||||
CHECK(env.render("{{ capitalize(name) }}", data) == "Peter");
|
||||
CHECK(env.render("{{ capitalize(city) }}", data) == "New york");
|
||||
CHECK(env.render("{{ capitalize(\"\") }}", data) == "");
|
||||
}
|
||||
|
||||
SUBCASE("range") {
|
||||
|
||||
Reference in New Issue
Block a user