blob: 55f2b938255c2001d86796a8911845266fb25ee3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
|