Doxygen
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 "dstring.h"
21#include "util.h"
22
23/*! \brief Class representing a HTML attribute. */
25{
26 HtmlAttrib(const DString &n,const DString &v) : name(n), value(v) {}
29};
30
31/*! \brief Class representing a list of HTML attributes. */
32class HtmlAttribList final : public std::vector<HtmlAttrib>
33{
34 public:
35 void mergeAttribute(const DString &optName,const DString &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 DString toString(DString *pAltValue = nullptr) const
50 {
51 DString result;
52 for (const auto &att : *this)
53 {
54 if (!att.value.empty()) // 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
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:89
Class representing a list of HTML attributes.
Definition htmlattrib.h:33
void mergeAttribute(const DString &optName, const DString &optValue)
Definition htmlattrib.h:35
DString toString(DString *pAltValue=nullptr) const
Definition htmlattrib.h:49
DirIterator begin(DirIterator it) noexcept
Definition dir.cpp:170
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:175
HtmlAttrib(const DString &n, const DString &v)
Definition htmlattrib.h:26
DString value
Definition htmlattrib.h:28
DString name
Definition htmlattrib.h:27
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3234
A bunch of utility functions.