]> 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, 20 Nov 2023 16:42:26 +0000 (11:42 -0500)
src/svgtiny_css.c

index 6d345a753dacf4764cb3353ce983a1a8e651241c..66ccd01d97a30eebc9d3bc3533be8770646d88dd 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);
 
 
 /**
@@ -580,3 +582,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;
+}