[JDEV] ambiguous libxode/j_strcat()
David Le Corfec
david.le-corfec at idealx.com
Tue Oct 24 04:19:15 CDT 2000
Gurer Ozen wrote:
> if(j_strcmp(xmlnode_get_attrib(x, "type"), "groupchat") == 0) ...
>
> NULL safe functions make it possible to chain those small functions.
> So even if there is no "type" attribute, if() check works correctly.
Ah ! I see ! I was confused by the name, j_strcmp().
It's not used as a comparator (lt, eq, gt) like strcmp,
but return whether strings are equal or not.
Yes, j_strcmp() is very handy when dealing with xml, but
adding specialized check functions would be cleaner and safer.
What about :
if (xmlnode_check_attrib_value(x, "type", "groupchat")) ...
(with NULL check on every parameter)
Another one :
if (j_strcmp(xmlnode_get_name(cur), "settype")==0) ...
=> if (xmlnode_check_name_value(cur, "settype")) ...
Isn't it a bit more human-readable ?
However, you could say that it tends to be less efficient:
type = xmlnode_get_tag_data(cur, "type");
if (j_strcmp(type, "session") == 0) ...
else if (j_strcmp(type, "packet") == 0) ...
=> if (xmlnode_check_tag_data(cur, "type", "session")) ...
else if (xmlnode_check_tag_data(cur, "type", "packet")) ...
Here you would do two xmlnode_get_tag_data(cur, "type") instead
of one, but IMHO such optimization is not worth the clarity
(give me a T3 first :)
I just hope that j_strcmp() isn't used where a real comparator
is expected. Or when one of the string is NULL where it *really*
shouldn't.
--
David Le Corfec
More information about the JDev
mailing list