The
PercentToBraceConverter class deals with converting traditional Python format strings (also known as
percent notation or
string interpolation syntax) into the more recently advocated template format mini-language.
Usage
String strToConvert = "'Hi, my name is %s' % name";
PercentToBraceConverter ptbc = new PercentToBraceConverter(strToConvert);
String convertedResult = ptbc.convert();
convertedResult would now be 'Hi, my name is {0!s}'.format(name)
Caveats
PercentToBraceConverter is not synchronized.
A PercentToBraceConverter instance also can't be reused or reset. If you want to convert another format string, you need to create a new instance.
If either the format string contents or the interpolation values span multiple lines, PercentToBraceConverter will currently (falsely) process them as being a single line. It can, however, process multiple lines containing multiple format strings where each format string is on one line.
@version 0.7
@author André Berg