]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny{.c,_internal.h}: intern SVG's XML namespace URI
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 12 Oct 2023 02:04:53 +0000 (22:04 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 20 Nov 2023 01:37:04 +0000 (20:37 -0500)
Intern the string "http://www.w3.org/2000/svg" in the parser state for
later use in libcss's node_name() select handler.

src/svgtiny.c
src/svgtiny_internal.h

index d16a761300ad7b0657eb7b59478a085af06b1cae..f6319305c3d2f1c76504766879b9ef55a9e219ea 100644 (file)
@@ -725,6 +725,19 @@ svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
 #include "svgtiny_strings.h"
 #undef SVGTINY_STRING_ACTION2
 
+       /* Intern SVG's xmlns separately because it's an lwc_string
+        * and not a dom_string. We initialize its pointer to NULL
+        * because the "cleanup:" test to see if it needs to be free'd
+        * looks for NULL. Returning a LIBDOM_ERROR on failure is not
+        * perfect but it's the closest of the available options. */
+       state.interned_svg_xmlns = NULL;
+       if (lwc_intern_string("http://www.w3.org/2000/svg",
+                             26,
+                             &state.interned_svg_xmlns) != lwc_error_ok) {
+               code = svgtiny_LIBDOM_ERROR;
+               goto cleanup;
+       }
+
        svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
        diagram->width = width;
        diagram->height = height;
@@ -762,6 +775,11 @@ cleanup:
                dom_string_unref(state.interned_##s);
 #include "svgtiny_strings.h"
 #undef SVGTINY_STRING_ACTION2
+
+       if (state.interned_svg_xmlns != NULL) {
+               lwc_string_unref(state.interned_svg_xmlns);
+       }
+
        return code;
 }
 
index 6b7bd92dffe0e8acafc57670492b82a32ad4742a..ba0db7029b30d719dc74d2dd401fdce9d1de0ac7 100644 (file)
@@ -68,6 +68,14 @@ struct svgtiny_parse_state {
 #include "svgtiny_strings.h"
 #undef SVGTINY_STRING_ACTION2
 
+       /* Where we store the interned copy of the SVG XML namespace,
+        *
+        *   http://www.w3.org/2000/svg
+        *
+        * We handle it separately it has a different type
+        * (lwc_string) than those above (dom_string).
+        */
+       lwc_string *interned_svg_xmlns;
 };
 
 struct svgtiny_list;