X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny_css.c;h=66ccd01d97a30eebc9d3bc3533be8770646d88dd;hb=dcb751a0f526be0332041fb4634974b1325686e9;hp=6d345a753dacf4764cb3353ce983a1a8e651241c;hpb=49fb0b4d04ca7e1bfb54a1021e469ed7ef7bf3f5;p=libsvgtiny.git diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index 6d345a7..66ccd01 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -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; +}