[stringtemplate-interest] null vs empty

Terence Parr parrt at cs.usfca.edu
Thu Feb 10 12:32:51 PST 2011


Hi.  http://bit.ly/e180eE shows that I think ST 3.2.1 sent null vs empty vs missing in a "bad" direction.  ST v4 behaves now that missing/null are same thing but different from empty. empty is {} or "" of <if(false)><endif> whereas missing is "no such attribute".  The new rules are

* null in a list ignored in iteration
* no separator generated for null values unless null=... option used
* null values not counted for i, i0
* template applied to missing or null attr yields ""
* empty values in iteration aren't ignored.

So, with 

st.add("values", new String[] {"x", "", "y"});

the template

<values; separator=" ">

yields: "x  y" with 2 not 1 space.  Empty "" is still there.

Same for this:

<values:{v|<if(v)>x<endif>}; separator=" ">

with 

st.add("values", new boolean[] {true, false, true});

yields "x  x".

See TestNullAndEmptyValues:

http://bit.ly/hZENBc

Sam reminded me this different than in v3.2.1 (though not < 3.2.1). Thought I'd point this out.

Ter


More information about the stringtemplate-interest mailing list