[stringtemplate-interest] Output string lengths..

John Snyders jjsnyders at rcn.com
Mon Dec 11 11:44:34 PST 2006


> -----Original Message-----
> From: stringtemplate-interest-bounces at antlr.org
> [mailto:stringtemplate-interest-bounces at antlr.org]On Behalf Of Terence
> Parr
> Sent: Monday, December 11, 2006 1:30 PM
> To: StringTemplate
> Subject: Re: [stringtemplate-interest] Output string lengths..
>
> On Dec 11, 2006, at 10:14 AM, Caleb Lyness wrote:
>
> > John Snyders wrote:
> >> Now that we have the format option you could do $d1;format("pad,
> >> 20")$, $d2;format("pad,30")$ and let the render grab the width
> >> from the format name but this is ugly.
> > The format specifier is sufficient for doing padding:
> >
> > c.f: java.util.Formatter
> >
> > Here is an example:
> >
> >         System.out.println("result="+String.format("|%-50s|",
> > "hello"));
> >         System.out.println("result="+String.format("|%50s|",
> > "hello"));
> >
> > Output
> > result=|hello                                             |
> > result=|                                             hello|
> >
>
> So,  We could do the following $name; format="%50s"$, right? then
> someone would have to make a string renderer, but that is easy.
>
> Ter

The trouble is that for a single type there is one renderer so it must
handle all needed formats.
$name;format="pad,20"$ then later $name;format="upperCase"$ A renderer for
the format option can do whatever it wants with the argument but in some
cases it would pass it to String.format and other times it will do something
else. BTW String.format/Formater is new in Java 1.5. The renderer must be
able to distinguish one argument value from another. If you wanted to use
the format argument as the argument to String.format I guess you could check
to see that it contains a '%'.

The other issues I raised about where format applies and why can't options
take multiple parameters are still unanswered.

-John



More information about the stringtemplate-interest mailing list