Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
href-attribute-helper.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Thomas Holder
5 *
6 * Copyright (C) 2022 Authors
7 *
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10
12
13namespace Inkscape {
14
20std::pair<char const *, char const *> getHrefAttribute(XML::Node const &node)
21{
22 if (auto value = node.attribute("href")) {
23 return {"href", value};
24 }
25
26 if (auto value = node.attribute("xlink:href")) {
27 return {"xlink:href", value};
28 }
29
30 return {"xlink:href", nullptr};
31}
32
38{
39 if (node.attribute("href")) {
40 node.setAttribute("href", value);
41 } else {
42 node.setAttribute("xlink:href", value);
43 }
44}
45
46} // namespace Inkscape
Non-owning reference to 'const char*' Main-purpose: avoid overloads of type f(char*,...
Interface for refcounted XML nodes.
Definition node.h:80
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
Inkscape::XML::Node * node
Helper class to stream background task notifications as a series of messages.
void setHrefAttribute(XML::Node &node, Util::const_char_ptr value)
If the 'href' attribute already exists for the given node, then set a new value for it.
std::pair< char const *, char const * > getHrefAttribute(XML::Node const &node)
Get the 'href' or 'xlink:href' (fallback) attribute from an XML node.