[stringtemplate-interest] Closing in on a version 4 release

Terence Parr parrt at cs.usfca.edu
Fri Jan 14 12:07:39 PST 2011


Added new ST.format method.

given,

int[] num =
    new int[] {3,9,20,2,1,4,6,32,5,6,77,888,2,1,6,32,5,6,77,
        4,9,20,2,1,4,63,9,20,2,1,4,6,32,5,6,77,6,32,5,6,77,
        3,9,20,2,1,4,6,32,5,6,77,888,1,6,32,5};
String t =
    ST.format(30, "int <%1>[] = { <%2; wrap, anchor, separator=\", \"> };", "a", num);
System.out.println(t);

You get:

int a[] = { 3, 9, 20, 2, 1, 4, 
            6, 32, 5, 6, 77, 888, 
            2, 1, 6, 32, 5, 6, 
            77, 4, 9, 20, 2, 1, 
            4, 63, 9, 20, 2, 1, 
            4, 6, 32, 5, 6, 77, 
            6, 32, 5, 6, 77, 3, 
            9, 20, 2, 1, 4, 6, 
            32, 5, 6, 77, 888, 
            1, 6, 32, 5 };

let's see MessageFormat.format do that!

Ter



More information about the stringtemplate-interest mailing list