]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny_css.c: implement node_has_id() select handler
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 12 Oct 2023 22:28:40 +0000 (18:28 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 9 Jun 2025 01:13:06 +0000 (21:13 -0400)
src/svgtiny_css.c

index 937484023eceea228395e58945354c5e8dc58ab4..5eb53088ffcb4235399806c8426c7617ea7a5707 100644 (file)
@@ -19,6 +19,8 @@ static css_error node_has_name(void *pw, void *node,
                const css_qname *qname, bool *match);
 static css_error node_has_class(void *pw, void *node,
                lwc_string *name, bool *match);
+static css_error node_has_id(void *pw, void *node,
+               lwc_string *name, bool *match);
 
 
 /**
@@ -578,3 +580,41 @@ css_error node_has_class(void *pw, void *node,
        dom_element_has_class((dom_node *)node, name, match);
        return CSS_OK;
 }
+
+
+/**
+ * Test the given node for the given id
+ *
+ * This will return true (via the "match" pointer) if the libdom node
+ * has the given id. The comparison is case-sensitive. It corresponds
+ * to node#id in CSS.
+ *
+ * \param pw       Pointer to the current SVG parser state
+ * \param node     Libdom SVG node to test
+ * \param name     Id to check for
+ * \param match    Pointer to the test result
+ *
+ * \return Always returns CSS_OK
+ */
+css_error node_has_id(void *pw, void *node,
+               lwc_string *name, bool *match)
+{
+       dom_string *attr;
+       dom_exception err;
+       struct svgtiny_parse_state *state;
+
+       attr = NULL;    /* a priori the "id" attribute may not exist */
+       *match = false; /* default to no match */
+
+       state = (struct svgtiny_parse_state *)pw;
+       err = dom_element_get_attribute((dom_node *)node,
+                               state->interned_id, &attr);
+       if (err != DOM_NO_ERR || attr == NULL) {
+               return CSS_OK;
+       }
+
+       *match = dom_string_lwc_isequal(attr, name);
+       dom_string_unref(attr);
+
+       return CSS_OK;
+}