[antlr-interest] why "null" does not work (String Template)
Kay Röpke
kroepke at classdump.org
Sat Aug 16 06:27:04 PDT 2008
Hi!
(setting reply-to to stringtemplate-interest because that's the
appropriate place for this question).
On Aug 16, 2008, at 10:29 AM, gaochunguang wrote:
>
> StringTemplate st = new
> StringTemplate("<chars; wrap, null=\"0\">",
> AngleBracketTemplateLexer.class);
> st.setAttribute("chars", "a");
> st.setAttribute("chars", "b");
> st.setAttribute("chars", "c");
> st.setAttribute("chars", null);
> st.setAttribute("chars", "e");
> st.setAttribute("chars", "f");
> System.out.println(st.toString());
>
> output is abcef.
the setAttribute method ignores anything with a null value. I'm not
sure what the rationale is behind that, but by writing it like:
StringTemplate st = new
StringTemplate("<chars; wrap, null=\"0\">",
AngleBracketTemplateLexer.class);
st.setAttribute("chars", new String[] {"a", "b", "c", null,
"e", "f"});
System.out.println(st.toString());
you get the output:
abc0ef
I believe ST should check if the attribute you want to set already is
a multivalue container before discarding null values (but not null
names obviously) in setAttribute(Object, Object), because in the
current implementation it's not behaving consistently, as shown above.
cheers,
-k
--
Kay Röpke
http://classdump.org/
More information about the antlr-interest
mailing list