summaryrefslogtreecommitdiffstats
path: root/src/xml/node-fns.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:29:01 +0000
commit35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch)
tree657d15a03cc46bd099fc2c6546a7a4ad43815d9f /src/xml/node-fns.cpp
parentInitial commit. (diff)
downloadinkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz
inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/xml/node-fns.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/xml/node-fns.cpp b/src/xml/node-fns.cpp
new file mode 100644
index 0000000..c996cfd
--- /dev/null
+++ b/src/xml/node-fns.cpp
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/** @file
+ * TODO: insert short description here
+ *//*
+ * Authors: see git history
+ *
+ * Copyright (C) 2018 Authors
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+#ifdef HAVE_CONFIG_H
+#endif
+
+#include <map>
+#include <cstring>
+#include <string>
+#include <glib.h> // g_assert()
+
+#include "xml/node-iterators.h"
+#include "util/find-if-before.h"
+#include "node-fns.h"
+
+namespace Inkscape {
+namespace XML {
+
+/* the id_permitted stuff is a temporary-ish hack */
+
+namespace {
+
+bool id_permitted_internal(GQuark qname) {
+ char const *qname_s=g_quark_to_string(qname);
+ return !strncmp("svg:", qname_s, 4) || !strncmp("sodipodi:", qname_s, 9) ||
+ !strncmp("inkscape:", qname_s, 9);
+}
+
+
+bool id_permitted_internal_memoized(GQuark qname) {
+ typedef std::map<GQuark, bool> IdPermittedMap;
+ static IdPermittedMap id_permitted_names;
+
+ IdPermittedMap::iterator found;
+ found = id_permitted_names.find(qname);
+ if ( found != id_permitted_names.end() ) {
+ return found->second;
+ } else {
+ bool permitted=id_permitted_internal(qname);
+ id_permitted_names[qname] = permitted;
+ return permitted;
+ }
+}
+
+}
+
+bool id_permitted(Node const *node) {
+ g_return_val_if_fail(node != nullptr, false);
+
+ if ( node->type() != ELEMENT_NODE ) {
+ return false;
+ }
+
+ return id_permitted_internal_memoized((GQuark)node->code());
+}
+
+struct node_matches {
+ node_matches(Node const &n) : node(n) {}
+ bool operator()(Node const &other) { return &other == &node; }
+ Node const &node;
+};
+
+// documentation moved to header
+Node *previous_node(Node *node) {
+ return node->prev();
+ using Inkscape::Algorithms::find_if_before;
+
+ if ( !node || !node->parent() ) {
+ return nullptr;
+ }
+
+ Node *previous=find_if_before<NodeSiblingIterator>(
+ node->parent()->firstChild(), nullptr, node_matches(*node)
+ );
+
+ g_assert(previous == nullptr
+ ? node->parent()->firstChild() == node
+ : previous->next() == node);
+
+ return previous;
+}
+
+}
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :