Jinja2Cpp icon indicating copy to clipboard operation
Jinja2Cpp copied to clipboard

Support for common python string functions

Open flexferrum opened this issue 5 years ago • 10 comments

It should be possible to call common python string functions (like split, partition etc.) from the Jinja2 templates. Like this:

{% set strings=text.split(' ') %}

flexferrum avatar Sep 05 '19 08:09 flexferrum

If is it that you say : https://docs.python.org/fr/3/library/stdtypes.html#str

I will work on it for Hacktoberfest :)

Servuc avatar Oct 07 '19 12:10 Servuc

Yes, exactly. Thanks! But before you start, lets discuss the exact set of methods to implement.

flexferrum avatar Oct 07 '19 12:10 flexferrum

Is it possible to first implement :

  • ~str.capitalize()~
  • [ ] str.center(width[, fillchar])
  • [ ] str.count(sub[, start[, end]])
  • [ ] str.endswith(suffix[, start[, end]])
  • [ ] str.find(sub[, start[, end]])
  • [ ] str.index(sub[, start[, end]])
  • [ ] str.isalnum()
  • [ ] str.isascii()
  • [ ] str.isnumeric()
  • [ ] str.islower()
  • [ ] str.isupper()
  • ~str.lower()~
  • [ ] str.replace(old, new[, count])
  • [ ] str.split(sep=None, maxsplit=-1)
  • [ ] str.splitlines([keepends])
  • [ ] str.startswith(prefix[, start[, end]])
  • [ ] str.strip([chars])
  • ~str.upper()~

Is it too much ? :)

Servuc avatar Oct 07 '19 18:10 Servuc

More over, For my personal dev, I will add a Dockerfile for compilation, do you want it too ?

Good coding day

Servuc avatar Oct 07 '19 18:10 Servuc

For my personal dev, I will add a Dockerfile for compilation, do you want it too ?

I'm using Windows environment for development so Docker isn't my choice...

flexferrum avatar Oct 07 '19 21:10 flexferrum

Is it too much ?

That's a good list. One thing I care about: there is implementation of some of this methods as a filters/testers (ex. https://github.com/jinja2cpp/Jinja2Cpp/blob/master/src/string_converter_filter.cpp ) So, there should be a way to reuse this implementation somehow.

flexferrum avatar Oct 07 '19 22:10 flexferrum

Hi,

For the Dockerfile, perhaps, just put it in wiki to prevent misunderstanding :)

Yes, I have see that file :) Thank you

Servuc avatar Oct 08 '19 06:10 Servuc

Hey,

Even if I have not ended that PR before the end of Hacktoberfest, I will finish it ;)

Have a good coding day

Servuc avatar Nov 01 '19 10:11 Servuc

Thank you!

flexferrum avatar Nov 01 '19 10:11 flexferrum

Can you share your approach in handling user-callable for strings? Looks like I need to do the same for MapAdapter. #178

flexferrum avatar Nov 05 '19 10:11 flexferrum