[fixup]s/property/attribute/

This commit is contained in:
tokyo4j 2025-04-11 17:32:54 +09:00
parent 5510d27904
commit e0993db702
4 changed files with 22 additions and 22 deletions

View file

@ -5,7 +5,7 @@
#include <libxml/tree.h>
/*
* Converts dotted properties into nested nodes.
* Converts dotted attributes into nested nodes.
* For example, the following node:
*
* <keybind name.action="ShowMenu" menu.action="root-menu"
@ -24,6 +24,6 @@
* </action>
* </keybind>
*/
void lab_xml_expand_dotted_props(xmlNode *root);
void lab_xml_expand_dotted_attributes(xmlNode *root);
#endif /* LABWC_XML_H */

View file

@ -5,16 +5,16 @@
#include "common/xml.h"
/*
* Converts a property A.B.C="X" into <C><B><A>X</A></B></C>
* Converts an attribute A.B.C="X" into <C><B><A>X</A></B></C>
*/
static xmlNode*
create_prop_tree(const xmlAttr *prop)
create_attribute_tree(const xmlAttr *attr)
{
if (!strchr((char *)prop->name, '.')) {
if (!strchr((char *)attr->name, '.')) {
return NULL;
}
gchar **parts = g_strsplit((char *)prop->name, ".", -1);
gchar **parts = g_strsplit((char *)attr->name, ".", -1);
int length = g_strv_length(parts);
xmlNode *root_node = NULL;
xmlNode *parent_node = NULL;
@ -35,7 +35,7 @@ create_prop_tree(const xmlAttr *prop)
parent_node = current_node;
}
xmlChar *content = xmlNodeGetContent(prop->children);
xmlChar *content = xmlNodeGetContent(attr->children);
xmlNodeSetContent(current_node, content);
xmlFree(content);
@ -45,7 +45,7 @@ create_prop_tree(const xmlAttr *prop)
/*
* Consider <keybind name.action="ShowMenu" x.position.action="1" y.position="2" />.
* These three properties are represented by following trees.
* These three attributes are represented by following trees.
* action(dst)---name
* action(src)---position---x
* action--------position---y
@ -86,7 +86,7 @@ merge_two_trees(xmlNode *dst, xmlNode *src)
}
void
lab_xml_expand_dotted_props(xmlNode *parent)
lab_xml_expand_dotted_attributes(xmlNode *parent)
{
xmlNode *old_first_child = parent->children;
xmlNode *prev_tree = NULL;
@ -95,13 +95,13 @@ lab_xml_expand_dotted_props(xmlNode *parent)
return;
}
for (xmlAttr *prop = parent->properties; prop;) {
/* Convert the property with dots into an xml tree */
xmlNode *tree = create_prop_tree(prop);
for (xmlAttr *attr = parent->properties; attr;) {
/* Convert the attribute with dots into an xml tree */
xmlNode *tree = create_attribute_tree(attr);
if (!tree) {
/* The property doesn't contain dots */
/* The attribute doesn't contain dots */
prev_tree = NULL;
prop = prop->next;
attr = attr->next;
continue;
}
@ -116,12 +116,12 @@ lab_xml_expand_dotted_props(xmlNode *parent)
prev_tree = tree;
}
xmlAttr *next_prop = prop->next;
xmlRemoveProp(prop);
prop = next_prop;
xmlAttr *next_attr = attr->next;
xmlRemoveProp(attr);
attr = next_attr;
}
for (xmlNode *node = parent->children; node; node = node->next) {
lab_xml_expand_dotted_props(node);
lab_xml_expand_dotted_attributes(node);
}
}

View file

@ -1416,7 +1416,7 @@ rcxml_parse_xml(struct buf *b)
}
struct parser_state init_state = {0};
xmlNode *root = xmlDocGetRootElement(d);
lab_xml_expand_dotted_props(root);
lab_xml_expand_dotted_attributes(root);
xml_tree_walk(root, &init_state);
xmlFreeDoc(d);
xmlCleanupParser();

View file

@ -90,7 +90,7 @@ struct test_case {
}};
static void
test_lab_xml_expand_dotted_props(void **state)
test_lab_xml_expand_dotted_attributes(void **state)
{
(void)state;
@ -99,7 +99,7 @@ test_lab_xml_expand_dotted_props(void **state)
NULL, NULL, 0);
xmlNode *root = xmlDocGetRootElement(doc);
lab_xml_expand_dotted_props(root);
lab_xml_expand_dotted_attributes(root);
xmlBuffer *buf = xmlBufferCreate();
xmlNodeDump(buf, root->doc, root, 0, 0);
@ -113,7 +113,7 @@ test_lab_xml_expand_dotted_props(void **state)
int main(int argc, char **argv)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_lab_xml_expand_dotted_props),
cmocka_unit_test(test_lab_xml_expand_dotted_attributes),
};
return cmocka_run_group_tests(tests, NULL, NULL);