[stringtemplate-interest] Spaces around template attributes
Steve Ebersole
steve at hibernate.org
Wed Apr 29 07:43:30 PDT 2009
I am trying to deal with extra spaces in my stringtemplate output when
attribute values used within the template are null/empty. I figure this
has to be a pretty common requirement, so I thought I'd ask here how to
accomplish this.
For example, I have a template like:
sortSpecification(sortKey,collationSpecification,orderingSpecification) ::= <<
<sortKey> <collationSpecification> <orderingSpecification>
>>
Only 'sortKey' is required in the corresponding (SQL-based) grammar. So
if you consider a call to this template with sortKey="a",
collationSpecification=null, orderingSpecification="asc" the output here
ends up being "a asc" (notice the 2 spaces between 'a' and 'asc').
So how to handle this such that the extra spaces are omitted? I
understand I *can* do something like:
sortSpecification(sortKey,collationSpecification,orderingSpecification) ::= <<
<sortKey><if(collationSpecification)>
<collationSpecification><endif><if(orderingSpecification)>
<orderingSpecification><endif>
>>
But personally I think that starts detracting from the readability of
the expression.
--
Steve Ebersole <steve at hibernate.org>
Hibernate.org
More information about the stringtemplate-interest
mailing list