[stringtemplate-interest] [ST4] Specify the encoding in the template group file

Udo Borkowski ub at abego-software.de
Thu Jan 27 08:24:26 PST 2011


Hi,

I suggest to specify the encoding/charset of a file in the file itself. This follows the same arguments as for the delimiter:

> why are we doing
> 
> STGroup g = new STGroupFile("t.stg", "ISO-8859-1", '$', '$');
> 
> when the file itself and not the code should determine what the encoding is. the code should not care. If we change the encoding in the file, the code no longer works. (Ter, bold stuff by Udo)


I suggest to add a new (optional) group statement the group file must start with (if defined). If it is missing the (platform specific) default encoding is used.

Possible syntax

	'encoding' STRING

For the GroupDir case the "group.config" file could be used again. However we may consider if the individual template files may specify individual charsets, too. (Note: this is different from the "delimiter" case where all template files share the same delimiters)

BUT: as I am writing this I noticed that this is very much like the stuff in the XML preamble:

> <?xml encoding='ISO-8859-1'?>

Maybe we should do something similar. What about making the group file (optionally) start with something like this:

	<st(version="4.0", encoding="ISO-8859-1")>

Looks familiar?!

This "template call" style also gives us the option to add more information later.


Udo

P.S.: Using such a well defined file content prefix "<st(" will probably also allows us to support "encoding autodetection" (http://www.w3.org/TR/REC-xml/#sec-guessing) in the future.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110127/4df35791/attachment.html 


More information about the stringtemplate-interest mailing list