[stringtemplate-interest] formatting the last element of a list
Nate
misc at n4te.com
Tue May 29 15:44:01 PDT 2007
Try...
public Object trunc (Object attribute) {
if (attribute == null) return null;
attribute = convertAnythingIteratableToIterator(attribute);
if (attribute instanceof Iterator) {
Iterator it = (Iterator)attribute;
// This is lazy. Should implement our own iterator that
wraps the attribute instead.
List values = new ArrayList();
while (it.hasNext())
values.add(it.next());
if (values.size() > 0) values.remove(values.size() - 1);
return values;
}
return null;
}
George Berger wrote:
> I tried that build, stringtemplate-05-03-2007.15, but got the same
> result. I poked around in the source code that came with it and found
> this in ASTExpr.java:
>
> /** Return all but the last element. trunc(x)=null if x is single-valued. */
> public Object trunc(Object attribute) {
> return null; // not impl.
> }
>
> Looks like it's not quite all there yet.
>
> George
>
> On 5/29/07, Terence Parr <parrt at cs.usfca.edu> wrote:
>
>> You need the latest build. 3.0 doesn't have this feature.
>>
>> http://www.stringtemplate.org/download/build
>>
>> Ter
>> On May 29, 2007, at 2:55 PM, George Berger wrote:
>>
>>
>>>> Try trunc(list) :)
>>>>
>>> I tried this but got nothing back. Here's my test program:
>>>
>>> names [$names$].
>>>
>>> first(names) [$first(names)$].
>>> rest(names) [$rest(names)$].
>>>
>>> trunc(names) [$trunc(names)$].
>>> last(names) [$last(names)$].
>>>
>>> Here's the output:
>>>
>>> names [JoeBobAlice].
>>>
>>> first(names) [Joe].
>>> rest(names) [BobAlice].
>>>
>>> trunc(names) [].
>>> last(names) [Alice].
>>>
>>> I'm using stringtemplate-3.0.jar. Do I need something more recent?
>>>
>>> George
>>> _______________________________________________
>>> stringtemplate-interest mailing list
>>> stringtemplate-interest at antlr.org
>>> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>>>
>> _______________________________________________
>> stringtemplate-interest mailing list
>> stringtemplate-interest at antlr.org
>> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>>
>>
>
>
>
>
More information about the stringtemplate-interest
mailing list