Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. StringTemplate in QT or C++?
Forum Updated to NodeBB v4.3 + New Features

StringTemplate in QT or C++?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 962 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by mbruel
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The grantlee project might be what you are looking for.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by
        #3

        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/)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Depending on your needs you also have mustache which is lightweight.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • mbruelM Offline
            mbruelM Offline
            mbruel
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved