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