[stringtemplate-interest] [antlr-interest] why "null" does not work (String Template)
gaochunguang
gaochunguang at 163.com
Wed Aug 20 01:46:30 PDT 2008
thank you.
----- Original Message -----
From: "Kay Röpke" <kroepke at classdump.org>
To: "gaochunguang" <gaochunguang at 163.com>
Cc: "ANTLR-Interest Interest" <antlr-interest at antlr.org>
Sent: Saturday, August 16, 2008 9:27 PM
Subject: Re: [antlr-interest] why "null" does not work (String Template)
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 stringtemplate-interest
mailing list