[stringtemplate-interest] Output string lengths..
Caleb Lyness
caleb.lyness at ezswitch.net
Mon Dec 11 14:26:38 PST 2006
John Snyders 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.
Trouble? Is this not a user/ system implementers problem?
One could use a hash table to look up the operator names
and default to String.format. Perhaps the implementor wants to support the
following: pad(20,'x') or remove('abc')... or whatever... they will do
that if
the want to.
> BTW String.format/Formater is new in Java 1.5.
Yes I noted that. There are other open source libraries available for
doing something similar
for earlier versions.... again that is a system implementers problem is
it not?
> 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
Surely to the attributes and the result of templates expansion?
I may have missed the point.
> and why can't options
> take multiple parameters are still unanswered.
>
I think I missed that... Can you point it out again.
Cheers
Caleb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061211/91e432d6/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3269 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20061211/91e432d6/attachment.bin
More information about the stringtemplate-interest
mailing list