]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny_css.c: case-insensitivity for node_has_attribute_substring()
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 17 Oct 2023 01:19:04 +0000 (21:19 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 20 Nov 2023 16:42:26 +0000 (11:42 -0500)
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.

src/svgtiny_css.c

index 7e096487f14ac33e1e0f7ad37874ddf553e71b92..de82a835071e602853810ad0f5e6c38554891fdc 100644 (file)
@@ -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