svnno****@sourc*****
svnno****@sourc*****
Fri Sep 11 12:37:18 JST 2009
Revision: 3840 http://sourceforge.jp/projects/kazehakase/svn/view?view=rev&revision=3840 Author: ikezoe Date: 2009-09-11 12:37:18 +0900 (Fri, 11 Sep 2009) Log Message: ----------- * src/kz-xml.c: Add kz_xml_attr_new. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/src/kz-xml.c Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2009-09-11 03:37:17 UTC (rev 3839) +++ kazehakase/trunk/ChangeLog 2009-09-11 03:37:18 UTC (rev 3840) @@ -1,8 +1,9 @@ -2009-09-10 Hiroyuki Ikezoe <poinc****@ikezo*****> +2009-09-11 Hiroyuki Ikezoe <poinc****@ikezo*****> * src/utils/kz-fonts-utils.[ch], src/prefs/prefs_font.c: Now font list are obtained with pango functions. + * src/kz-xml.c: Add kz_xml_attr_new. 2009-09-10 Hiroyuki Ikezoe <poinc****@ikezo*****> Modified: kazehakase/trunk/src/kz-xml.c =================================================================== --- kazehakase/trunk/src/kz-xml.c 2009-09-11 03:37:17 UTC (rev 3839) +++ kazehakase/trunk/src/kz-xml.c 2009-09-11 03:37:18 UTC (rev 3840) @@ -52,7 +52,7 @@ object_class->dispose = dispose; object_class->finalize = finalize; - g_type_class_add_private (object_class, sizeof(KzXMLPrivate)); + g_type_class_add_private(object_class, sizeof(KzXMLPrivate)); } @@ -258,7 +258,7 @@ g_return_val_if_fail(KZ_IS_XML(xml), FALSE); if (buffer == NULL) return FALSE; - priv = KZ_XML_GET_PRIVATE (xml); + priv = KZ_XML_GET_PRIVATE(xml); context = priv->context; if (!context) { @@ -284,7 +284,7 @@ g_warning("XML parse error!: %s", error->message); g_error_free(error); } - g_markup_parse_context_free (context); + g_markup_parse_context_free(context); priv->context = NULL; return ret; @@ -325,7 +325,7 @@ g_return_val_if_fail(file && *file, FALSE); str = kz_xml_node_to_xml(xml->root); - success =g_file_set_contents(file, str, -1, NULL); + success = g_file_set_contents(file, str, -1, NULL); g_free(str); return success; @@ -439,6 +439,18 @@ } +static KzXMLAttr * +kz_xml_attr_new (const gchar *name, const gchar *value) +{ + KzXMLAttr *attr; + + attr = g_slice_new0(KzXMLAttr); + attr->name = g_strdup(name); + attr->value = g_strdup(value); + + return attr; +} + static void kz_xml_attr_free (KzXMLAttr *attr) { @@ -472,8 +484,8 @@ } if (!node->children) - g_string_append(gstr, "/"); - g_string_append(gstr, ">"); + g_string_append_c(gstr, '/'); + g_string_append_c(gstr, '>'); } if (element || node->type == KZ_XML_NODE_DOC_ROOT) @@ -602,10 +614,7 @@ g_return_val_if_fail(element, FALSE); g_return_val_if_fail(element->name, FALSE); - if (!strcmp(element->name, name)) - return TRUE; - else - return FALSE; + return (!strcmp(element->name, name)); } static gint @@ -694,9 +703,7 @@ if (!found) { - attr = g_slice_new0(KzXMLAttr); - attr->name = g_strdup(name); - attr->value = g_strdup(value); + attr = kz_xml_attr_new(name, value); element->attrs = g_list_append(element->attrs, attr); } } @@ -752,10 +759,7 @@ if (!list) return NULL; list = g_list_previous(list); - if (list) - return list->data; - else - return NULL; + return list ? list->data : NULL; } @@ -773,10 +777,7 @@ { g_return_val_if_fail(node, NULL); - if (node->children) - return node->children->data; - else - return NULL; + return node->children ? node->children->data : NULL; } @@ -789,10 +790,7 @@ list = g_list_last(node->children); - if (list) - return list->data; - else - return NULL; + return list ? list->data : NULL; } @@ -844,10 +842,7 @@ { g_return_val_if_fail(node, FALSE); - if (node->type == KZ_XML_NODE_ELEMENT) - return TRUE; - else - return FALSE; + return (node->type == KZ_XML_NODE_ELEMENT); } @@ -924,10 +919,7 @@ { g_return_val_if_fail(node, FALSE); - if (node->type == KZ_XML_NODE_TEXT) - return TRUE; - - return FALSE; + return (node->type == KZ_XML_NODE_TEXT); } @@ -939,8 +931,6 @@ g_free(node->content); node->content = g_strdup(text); - - return; } @@ -1074,7 +1064,7 @@ str = (char*)content; i = j = strlen("<![CDATA["); - while(str[i] != '\0') + while (str[i] != '\0') { if(str[i] == ']' && str[i+3] == '\0') { @@ -1090,3 +1080,4 @@ return plain_text; } +