svnno****@sourc*****
svnno****@sourc*****
Sun Feb 22 18:46:16 JST 2009
Revision: 3752 http://svn.sourceforge.jp/view?root=kazehakase&view=rev&rev=3752 Author: ikezoe Date: 2009-02-22 18:46:16 +0900 (Sun, 22 Feb 2009) Log Message: ----------- * src/kz-xml.[ch]: Added kz_xml_node_has_attr(). Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/src/kz-xml.c kazehakase/trunk/src/kz-xml.h Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2009-02-22 02:27:22 UTC (rev 3751) +++ kazehakase/trunk/ChangeLog 2009-02-22 09:46:16 UTC (rev 3752) @@ -3,6 +3,7 @@ * data/kazehakase.desktop: Remove extension from icon entry. * module/embed/gecko/kz-mozdownloader.c: Change property name. filename -> file-name. + * src/kz-xml.[ch]: Added kz_xml_node_has_attr(). 2009-02-21 Hiroyuki Ikezoe <poinc****@ikezo*****> Modified: kazehakase/trunk/src/kz-xml.c =================================================================== --- kazehakase/trunk/src/kz-xml.c 2009-02-22 02:27:22 UTC (rev 3751) +++ kazehakase/trunk/src/kz-xml.c 2009-02-22 09:46:16 UTC (rev 3752) @@ -614,29 +614,50 @@ return FALSE; } +static gint +compare_attr_name (gconstpointer a, gconstpointer b) +{ + const KzXMLAttr *attr_a = a; + const gchar *attr_name = b; + return g_strcmp0(attr_a->name, attr_name); +} + + +gboolean +kz_xml_node_has_attr (KzXMLNode *node, const gchar *attr_name) +{ + KzXMLElement *element; + GList *list; + + g_return_val_if_fail(node, FALSE); + g_return_val_if_fail(node->type == KZ_XML_NODE_ELEMENT, FALSE); + g_return_val_if_fail(attr_name, FALSE); + + element = node->content; + g_return_val_if_fail(element, FALSE); + + list = g_list_find_custom(element->attrs, attr_name, + (GCompareFunc)compare_attr_name); + return list ? TRUE : FALSE; +} + const gchar * kz_xml_node_get_attr (KzXMLNode *node, const gchar *attr_name) { KzXMLElement *element; GList *list; - g_return_val_if_fail(node, NULL); - g_return_val_if_fail(node->type == KZ_XML_NODE_ELEMENT, NULL); - g_return_val_if_fail(attr_name, NULL); + g_return_val_if_fail(node, FALSE); + g_return_val_if_fail(node->type == KZ_XML_NODE_ELEMENT, FALSE); + g_return_val_if_fail(attr_name, FALSE); element = node->content; - g_return_val_if_fail(element, NULL); + g_return_val_if_fail(element, FALSE); - for (list = element->attrs; list; list = g_list_next(list)) - { - KzXMLAttr *attr = list->data; - - if (!strcmp(attr_name, attr->name)) - return attr->value; - } - - return NULL; + list = g_list_find_custom(element->attrs, attr_name, + (GCompareFunc)compare_attr_name); + return list ? ((KzXMLAttr*)list->data)->value : NULL; } Modified: kazehakase/trunk/src/kz-xml.h =================================================================== --- kazehakase/trunk/src/kz-xml.h 2009-02-22 02:27:22 UTC (rev 3751) +++ kazehakase/trunk/src/kz-xml.h 2009-02-22 09:46:16 UTC (rev 3752) @@ -130,6 +130,8 @@ const gchar *kz_xml_node_name (KzXMLNode *node); gboolean kz_xml_node_name_is (KzXMLNode *node, const gchar *name); +gboolean kz_xml_node_has_attr (KzXMLNode *node, + const gchar *attr_name); const gchar *kz_xml_node_get_attr (KzXMLNode *node, const gchar *attr_name); void kz_xml_node_set_attr (KzXMLNode *node,