[stringtemplate-interest] stripping newlines in attributes..

Kay Roepke kroepke at classdump.org
Sat Oct 14 09:20:20 PDT 2006


CC'ing the list for the archives.

On 14. Oct 2006, at 18:03 Uhr, Robert Hill wrote:

> Thanks Kay,
> I do want it to strip nulls, not newlines - I have RTFM'd , just I  
> can't
> seem to get it to work.

Robert, I'm sorry. I have no idea where I got the newline stuff  
from ;) Must have been confused...lack of coffee perhaps.

> I have a template that build an sql statement, which takes an  
> attribute
> that's is ArrayList<> , and I add more than one element so I can  
> build up a
> select  with data coming from different tables. However, if the  
> array list
> is populated with 2 element and the 2nd element is a null, the
> separator=",\n" I have in the template is outputting a trailing  
> comma I
> don't want. So I thought I'd strip out null elements from the  
> attribute so
> In theory the attribute would only ever hold 1 array list, and the
> separator= wouldn't output a newline.

That's what it's for, yes.

> Im using Antlr V3.0b4, and the stringtemplate that goes with it.

That's the problem. The ST jar shipped with b4 is missing the length/ 
strip functions for some reason.
This came up a couple of weeks ago on antlr-interest, too. Ter and I  
have no idea why the functions
weren't included, they should've been, as the ObjC target depends on  
length.
Anyhow, if you use ST 3.0 instead, it should work.

> Mappings holds more than one array list, and each map then holds an
> arraylist with multiple members.
> (I don't expect you to debug the template! Just thought it would be  
> easier
> if you saw it!)

:)

> Any pointers would be welcome! Or an example with strip() in it... c

Typed-in-mail-disclaimer etc.:

select(mappings, param) ::= <<
SELECT
	<strip(mappings):{map | <strip(map.membersWithoutKeys):{mem |  
<map.table>.<mem.column>}>}; separator=",\r\n">
...etc.
 >>

should do the trick.

HTH,
-k





More information about the stringtemplate-interest mailing list