Debian Codegraph @

Server/Web/HtmlTag.cpp

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <sstream>
22
23 #include "Server/Web/HtmlTag.h"
24
25 namespace Server { namespace Web
26 {
27 HtmlTag HtmlTag::AddAttribute(const std::string& name, const std::string& value)
28 {
29 if (name.size() > 0)
30 {
31 this->attributes[name] += value;
32 }
33 return *this;
34 }
35
36 std::ostream& operator<<(std::ostream& stream, const HtmlTag& tag)
37 {
38 if (tag.name.size() > 0)
39 {
40 stream << "<" << tag.name;
41
42 if (tag.id.size() > 0)
43 {
44 stream << " id=\"" << tag.id << "\"";
45 }
46
47 if (tag.classes.size() > 0)
48 {
49 stream << " class=\"";
50 for (auto& c : tag.classes)
51 {
52 stream << " " << c;
53 }
54 stream << "\"";
55 }
56
57 for (auto& attribute : tag.attributes)
58 {
59 stream << " " << attribute.first;
60 if (attribute.second.size() > 0)
61 {
62 stream << "=\"" << attribute.second << "\"";
63 }
64 }
65
66 stream << ">";
67
68 if (tag.childTags.size() == 0 && tag.content.size() == 0 && (
69 tag.name.compare("input") == 0 ||
70 tag.name.compare("link") == 0 ||
71 tag.name.compare("meta") == 0 ||
72 tag.name.compare("br") == 0))
73 {
74 return stream;
75 }
76 }
77
78 for (auto& child : tag.childTags)
79 {
80 stream << child;
81 }
82
83 stream << tag.content;
84
85 if (tag.name.size() > 0)
86 {
87 stream << "</" << tag.name << ">";
88 }
89 return stream;
90 }
91 }} // namespace Server::Web