summaryrefslogtreecommitdiffstats
path: root/src/xml/href-attribute-helper.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
commitc853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch)
tree7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/xml/href-attribute-helper.cpp
parentInitial commit. (diff)
downloadinkscape-upstream.tar.xz
inkscape-upstream.zip
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/xml/href-attribute-helper.cpp')
-rw-r--r--src/xml/href-attribute-helper.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/xml/href-attribute-helper.cpp b/src/xml/href-attribute-helper.cpp
new file mode 100644
index 0000000..55f2b93
--- /dev/null
+++ b/src/xml/href-attribute-helper.cpp
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Authors:
+ * Thomas Holder
+ *
+ * Copyright (C) 2022 Authors
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include "href-attribute-helper.h"
+
+namespace Inkscape {
+
+/**
+ * Get the 'href' or 'xlink:href' (fallback) attribute from an XML node.
+ *
+ * @return The observed key and its value
+ */
+std::pair<char const *, char const *> getHrefAttribute(XML::Node const &node)
+{
+ if (auto value = node.attribute("href")) {
+ return {"href", value};
+ }
+
+ if (auto value = node.attribute("xlink:href")) {
+ return {"xlink:href", value};
+ }
+
+ return {"xlink:href", nullptr};
+}
+
+/**
+ * If the 'href' attribute already exists for the given node, then set a new
+ * value for it. Otherwise set the value for 'xlink:href'.
+ */
+void setHrefAttribute(XML::Node &node, Util::const_char_ptr value)
+{
+ if (node.attribute("href")) {
+ node.setAttribute("href", value);
+ } else {
+ node.setAttribute("xlink:href", value);
+ }
+}
+
+} // namespace Inkscape