Doxygen
Toggle main menu visibility
Loading...
Searching...
No Matches
htmlattrib.h
Go to the documentation of this file.
1
/******************************************************************************
2
*
3
* Copyright (C) 1997-2026 by Dimitri van Heesch.
4
*
5
* Permission to use, copy, modify, and distribute this software and its
6
* documentation under the terms of the GNU General Public License is hereby
7
* granted. No representations are made about the suitability of this software
8
* for any purpose. It is provided "as is" without express or implied warranty.
9
* See the GNU General Public License for more details.
10
*
11
*/
12
13
#ifndef HTMLATTRIB_H
14
#define HTMLATTRIB_H
15
16
#include <vector>
17
18
#include "
dstring.h
"
19
#include "
util.h
"
20
21
/*! \brief Class representing a HTML attribute. */
22
struct
HtmlAttrib
23
{
24
HtmlAttrib
(
const
DString
&n,
const
DString
&v) :
name
(n),
value
(v) {}
25
DString
name
;
26
DString
value
;
27
};
28
29
/*! \brief Class representing a list of HTML attributes. */
30
class
HtmlAttribList
final :
public
std::vector<HtmlAttrib>
31
{
32
public
:
33
void
mergeAttribute
(
const
DString
&optName,
const
DString
&optValue,
bool
prepend =
false
)
34
{
35
auto
it = std::find_if(
begin
(),
end
(),
36
[&optName](
const
auto
&opt) {
return
opt.name==optName; });
37
if
(it!=
end
())
// attribute name already in the list: append values
38
{
39
if
(prepend)
40
{
41
it->value = optValue +
" "
+ it->value;
42
}
43
else
44
{
45
it->value +=
" "
+ optValue;
46
}
47
}
48
else
// attribute name not yet in the list
49
{
50
emplace_back(optName,optValue);
51
}
52
}
53
54
DString
toString
(
DString
*pAltValue =
nullptr
)
const
55
{
56
DString
result;
57
for
(
const
auto
&att : *
this
)
58
{
59
if
(!att.value.empty())
// ignore attribute without values as they
60
// are not XHTML compliant, with the exception
61
// of the alt attribute with the img tag
62
{
63
if
(att.name==
"alt"
&& pAltValue)
// optionally return the value of alt separately
64
// need to convert <img> to <object> for SVG images,
65
// which do not support the alt attribute
66
{
67
*pAltValue = att.value;
68
}
69
else
70
{
71
result+=
" "
+att.name+
"=\""
+
convertToXML
(att.value)+
"\""
;
72
}
73
}
74
else
if
(att.name==
"open"
)
75
{
76
// The open attribute is a boolean attribute.
77
// Specifies that the details should be visible (open) to the user
78
// As it is a boolean attribute the initialization value is of no interest
79
result+=
" "
+att.name+
"=\"true\""
;
80
}
81
else
if
(att.name==
"nowrap"
)
// In XHTML, attribute minimization is forbidden, and the nowrap attribute must be defined as <td nowrap="nowrap">.
82
{
83
result+=
" "
+att.name+
"=\"nowrap\""
;
84
}
85
}
86
return
result;
87
}
88
89
};
90
91
#endif
92
DString
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition
dstring.h:84
HtmlAttribList
Class representing a list of HTML attributes.
Definition
htmlattrib.h:31
HtmlAttribList::mergeAttribute
void mergeAttribute(const DString &optName, const DString &optValue, bool prepend=false)
Definition
htmlattrib.h:33
HtmlAttribList::toString
DString toString(DString *pAltValue=nullptr) const
Definition
htmlattrib.h:54
begin
DirIterator begin(DirIterator it) noexcept
Definition
dir.cpp:176
end
DirIterator end(const DirIterator &) noexcept
Definition
dir.cpp:181
dstring.h
HtmlAttrib::HtmlAttrib
HtmlAttrib(const DString &n, const DString &v)
Definition
htmlattrib.h:24
HtmlAttrib::value
DString value
Definition
htmlattrib.h:26
HtmlAttrib::name
DString name
Definition
htmlattrib.h:25
convertToXML
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition
util.cpp:3232
util.h
A bunch of utility functions.
src
htmlattrib.h
Generated by
1.19.0