StringTemplate in QT or C++?
-
wrote on 24 Sept 2018, 17:26 last edited by mbruel
Hi,
I'm porting a java application that is using StringTemplate: https://theantlrguy.atlassian.net/wiki/spaces/ST/pages/1409116/Five+minute+Introduction
Basically it is loading a file that has some keywords that will be replaced. It is also able to iterate over some maps.
Any idea if there is a QT or C++ equivalent?
Cheers
PS: here is an example of the template file:$projectName$ $title$ some fixed property $myMap:{$it.myKey$ $it.myValue$}; separator={$newLine$}$
I'd just need to give the good strings for projectName, title and newLine and provide the map myMap
PS: I could parse the template file and replace the strings with all the values stored in a QMap, my problem would then be how to iterate the map when I'm only getting its name and the attribute's name (in fact it is not a map but a list of objects) as strings.
-
Hi,
The grantlee project might be what you are looking for.
-
wrote on 25 Sept 2018, 09:16 last edited by
Thanks for the link.
I'd prefer something lighter. I may adapt something from cpptempl, removing the boost library. (http://ginstrom.com/scribbles/2010/10/30/cpptempl-a-template-language-for-c/comment-page-1/) -
Depending on your needs you also have mustache which is lightweight.
-
wrote on 26 Sept 2018, 05:38 last edited by
Cheers but it is too simple, I need to handle loops too. For the moment my client is happy to not use the string templating on the c++ version so I'll think about it again later...
4/5