Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions to convert string to number #22

Closed
ludekvodicka opened this issue Feb 28, 2018 · 2 comments
Closed

Functions to convert string to number #22

ludekvodicka opened this issue Feb 28, 2018 · 2 comments

Comments

@ludekvodicka
Copy link
Contributor

Because Inja now offers several useful function it would be great to add also functions to convert string to number.

I currently have these functions named double(x) and integer(x) with following test

nlohmann::json data;
data["val1"] = "5";
data["val2"] = "-5";

InjaStringType res = inja::render("{%if integer(val1) >= 0%}yes{%else%}no{%endif%}", data);
TEST_CHECK_EQUAL(res, "yes");

res = inja::render("{%if integer(val1) < 0%}yes{%else%}no{%endif%}", data);
TEST_CHECK_EQUAL(res, "no");

res = inja::render("{%if double(val2) >= 0%}yes{%else%}no{%endif%}", data);
TEST_CHECK_EQUAL(res, "no");

res = inja::render("{%if double(val2) < 0%}yes{%else%}no{%endif%}", data);
TEST_CHECK_EQUAL(res, "yes");

Are you interested in such PR?

@pantor
Copy link
Owner

pantor commented Mar 1, 2018

Already done!

@pantor pantor closed this as completed Mar 1, 2018
@ludekvodicka
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants