From: Michael Orlitzky Date: Tue, 17 Oct 2023 01:19:04 +0000 (-0400) Subject: src/svgtiny_css.c: case-insensitivity for node_has_attribute_substring() X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;ds=sidebyside;h=ed265576e5a9c4daf8e938548f3d18b106bd07fe;p=libsvgtiny.git src/svgtiny_css.c: case-insensitivity for node_has_attribute_substring() All of the CSS attribute selectors take a flag to make the comparison case-insensitive. Libcss doesn't support that yet, but in the case of node_has_attribute_substring(), factoring out the implementation and letting it take an "insensitive" flag will be of use to us when we implement the node_is_lang() select handler. --- diff --git a/src/svgtiny_css.c b/src/svgtiny_css.c index 7e09648..de82a83 100644 --- a/src/svgtiny_css.c +++ b/src/svgtiny_css.c @@ -1111,29 +1111,16 @@ css_error node_has_attribute_suffix(void *pw, void *node, /** - * Test the given node for an attribute whose value contains the - * given substring - * - * This will return true (via the "match" pointer) if the libdom node - * has an attribute with the given name and whose value contains the - * given substring. The comparison is case-sensitive. This corresponds - * to [attr*=value] 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 substring Value substring to check for - * \param match Pointer to the test result - * - * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot - * intern the attribute name (which usually indicates memory - * exhaustion) + * Implement node_has_attribute_substring() with optional case- + * insensitivity. This corresponds to [attr*=value i] in CSS and is + * not supported by libcss yet, but it allows us to factor out some + * common code. */ -css_error node_has_attribute_substring(void *pw, void *node, +static css_error _node_has_attribute_substring(void *pw, void *node, const css_qname *qname, lwc_string *substring, - bool *match) + bool *match, bool insensitive) { - UNUSED(pw); + UNUSED(pw); dom_string *name; dom_string *attr_val; dom_exception err; @@ -1174,7 +1161,13 @@ css_error node_has_attribute_substring(void *pw, void *node, * and the first thing we want to do is check to see if the * whole thing matches the substring. */ dom_string_unref(name); - *match = dom_string_lwc_isequal(attr_val, substring); + + if (insensitive) { + *match = dom_string_caseless_lwc_isequal(attr_val, substring); + } + else { + *match = dom_string_lwc_isequal(attr_val, substring); + } /* If not, check to see if an, uh, substring matches the * substring */ @@ -1202,6 +1195,33 @@ css_error node_has_attribute_substring(void *pw, void *node, return CSS_OK; } +/** + * Test the given node for an attribute whose value contains the + * given substring + * + * This will return true (via the "match" pointer) if the libdom node + * has an attribute with the given name and whose value contains the + * given substring. The comparison is case-sensitive. This corresponds + * to [attr*=value] 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 substring Value substring to check for + * \param match Pointer to the test result + * + * \return Returns CSS_OK if successful and CSS_NOMEM if we cannot + * intern the attribute name (which usually indicates memory + * exhaustion) + */ +css_error node_has_attribute_substring(void *pw, void *node, + const css_qname *qname, lwc_string *substring, + bool *match) +{ + return _node_has_attribute_substring(pw, node, qname, substring, + match, false); +} + /** * Test whether or not the given node is the document's root element