[stringtemplate-interest] Outputting '\n' line separators for other EOL convention.
Frédéric Delanoy
frederic.delanoy at gmail.com
Thu Feb 26 09:07:41 PST 2009
Hi,
I'd like to generate text so that "\n"-template separator always
produces UNIX-style EOL, regardless of the system the JVM is running
on.
( e.g. running on win32 produces "\r\n" EOLs)
A quick check in the code seems to indicate that the standard system
property "line.separator" is used (which is usually the good thing to
do)
I found 2 solutions:
- replacing after template "merge" all EOLs characters => rather
kludgy and suboptimal (e.g.
tmpl.toString().replace("\r\n","\n").replace("\r","\n"); )
- saving old sep, producing string, restoring old sep
String oldSep = System.getProperty("line.separator");
System.setProperty("line.separator", "\n");
String result = beaconsTemplate.toString();
System.setProperty("line.separator", oldSep);
-> dirty "hack"
Is there a way I could do this more properly using ST's API?
Frederic
More information about the stringtemplate-interest
mailing list