I am looking for a clean C ++ way to parse a string containing expressions enclosed in $ {} and build the resulting string from programmatically evaluated expressions.
Example: "Hello $ {user} from $ {host}" will be evaluated as "Hello foo from bar" if I implement a program so that "user" evaluates to "foo", etc.
The current approach that I think of consists of a state machine that eats one character at a time from a string and evaluates the expression after reaching '}'. Any tips or other suggestions?
Note: boost :: is welcome !:-)
Update Thanks for the first three sentences! Unfortunately, I made this example too simple! I need to examine the contents within $ {} so that it is not a simple search and replace. He might say $ {uppercase: foo}, and then I should use "foo" as the key in the hash map and then convert it to uppercase, but I tried to avoid the internal details of $ {} when writing the original question above. .. :-)
source share