[stringtemplate-interest] Outputting '\n' line separators for other EOL convention.
Terence Parr
parrt at cs.usfca.edu
Thu Feb 26 17:59:16 PST 2009
Hi. Call StringTemplateGroup.setStringTemplateWriter to return a
AutoIndentWriter using this ctor:
public AutoIndentWriter(Writer out, String newline) {
this.out = out;
indents.add(null); // s oftart with no indent
this.newline = newline;
}
not this one:
public AutoIndentWriter(Writer out) {
this(out, System.getProperty("line.separator"));
}
Should work great!
Ter
On Feb 26, 2009, at 9:07 AM, Frédéric Delanoy wrote:
> 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
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list