[stringtemplate-interest] [java] Padding again - <fill()> builtin

Caleb Lyness caleb.lyness at ezswitch.net
Mon Dec 17 13:22:02 PST 2007


Zenaan Harkness wrote:
> On Tue, Jun 06, 2006 at 11:56:54PM +0000, Terence Parr wrote:
>   
>> On Jun 7, 2006, at 12:17 AM, Anton Tagunov wrote:
>>
>>     
>>> Hello
>>>
>>> multivalued attribute, need to pad each value with spaces
>>> so that all become equal length on output.
>>>
>>> Where to do this: on java or ST side?
>>>       
>> For now, you'd have to do on the Java side.
>>
>> We could use a <fill()> built-in function that would fill until the  
>> end of line.
>>     
>
> Is anyone of a level of competency, and with a little time, to have a
> crack at a fill() builtin for ST?
>
> TIA
> Zen
>   
Using ST 3.1b you can use the following:

            AttributeRenderer formatRenderer = new AttributeRenderer() {
                private Locale locale = Locale.getDefault();
                public String toString(Object o) {
                    return o.toString();
                }
                public String toString(Object o, String formatStr) {   
               
                    return String.format(locale,formatStr,o.toString());
                }               
            };   


reportTemplates.registerRenderer(String.class,formatRenderer); ... etc ....

and something like:

| Line | Reason                                              | Record
details
-------------------------------------------------------------------------------
$report.errors: {error | | $error.lineIndex;format="%4s"$ |
$error.reason;format="%-51s"$ | $error.originalData$};separator="\n"$

with a little more imagination I am sure you can get what you want.

Cheers
     Caleb.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071217/1b1185af/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/20071217/1b1185af/attachment.bin 


More information about the stringtemplate-interest mailing list