X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fsvgtiny_css.c;h=0267325df7a7a7b202a36ffd1434e233a644469e;hb=dcd18c90ee670c7b341b6856aaf75e0e0dfd0d37;hp=66ccd01d97a30eebc9d3bc3533be8770646d88dd;hpb=dcb751a0f526be0332041fb4634974b1325686e9;p=libsvgtiny.git diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index 66ccd01..0267325 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -21,6 +21,8 @@ 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); +static css_error node_has_attribute(void *pw, void *node, + const css_qname *qname, bool *match); /** @@ -620,3 +622,46 @@ css_error node_has_id(void *pw, void *node, return CSS_OK; } + + +/** + * Test the given node for the given attribute + * + * This will return true (via the "match" pointer) if the libdom node + * has an attribute with the given name. The comparison is + * case-sensitive. It corresponds to node[attr] in CSS. + * + * \param pw Pointer to the current SVG parser state + * \param node Libdom SVG node to test + * \param qname Attribute name to check for + * \param match Pointer to the test result + * + * \return Returns CSS_OK if successful and CSS_NOMEM if anything + * goes wrong + */ +css_error node_has_attribute(void *pw, void *node, + const css_qname *qname, bool *match) +{ + UNUSED(pw); + dom_string *name; + dom_exception err; + + /* intern the attribute name as a dom_string so we can + * delegate to dom_element_has_attribute() */ + err = dom_string_create_interned( + (const uint8_t *) lwc_string_data(qname->name), + lwc_string_length(qname->name), + &name); + if (err != DOM_NO_ERR) { + return CSS_NOMEM; + } + + err = dom_element_has_attribute((dom_node *)node, name, match); + if (err != DOM_NO_ERR) { + dom_string_unref(name); + return CSS_OK; + } + + dom_string_unref(name); + return CSS_OK; +}