2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 #include "stg/common.h"
34 void appendTag(std::ostream& stream, const std::string& name, const T& value)
36 stream << "<" << name << " value=\"" << value << "\"/>";
41 void appendTag(std::ostream& stream, const std::string& name, size_t suffix, const T& value)
43 stream << "<" << name << suffix << " value=\"" << value << "\"/>";
48 void appendTag<uint8_t>(std::ostream& stream, const std::string& name, const uint8_t& value)
50 stream << "<" << name << " value=\"" << static_cast<unsigned>(value) << "\"/>";
55 void appendTag<int8_t>(std::ostream& stream, const std::string& name, const int8_t& value)
57 stream << "<" << name << " value=\"" << static_cast<int>(value) << "\"/>";
62 void appendAttr(std::ostream& stream, const std::string& name, const T& value)
64 stream << " " << name << "=\"" << value << "\"";
69 void appendAttr(std::ostream& stream, const std::string& name, size_t suffix, const T& value)
71 stream << " " << name << suffix << "=\"" << value << "\"";
76 void appendAttr<uint8_t>(std::ostream& stream, const std::string& name, const uint8_t& value)
78 stream << " " << name << "=\"" << static_cast<unsigned>(value) << "\"";
83 void appendAttr<int8_t>(std::ostream& stream, const std::string& name, const int8_t& value)
85 stream << " " << name << "=\"" << static_cast<int>(value) << "\"";
90 void appendResetableTag(std::ostream& stream, const std::string& name, const std::optional<T>& value)
93 appendTag(stream, name, value.value());
98 void appendResetableTag(std::ostream& stream, const std::string& name, size_t suffix, const std::optional<T>& value)
101 appendTag(stream, name, suffix, value.value());
104 template <typename T>
106 void appendResetableAttr(std::ostream& stream, const std::string& name, const std::optional<T>& value)
109 appendAttr(stream, name, value.value());
112 template <typename T>
114 void appendResetableAttr(std::ostream& stream, const std::string& name, size_t suffix, const std::optional<T>& value)
117 appendAttr(stream, name, suffix, value.value());
121 std::optional<std::string> maybeEncode(const std::optional<std::string>& value)
123 std::optional<std::string> res;
125 res = Encode12str(value.value());
130 std::optional<std::string> maybeIconv(const std::optional<std::string>& value, const std::string& fromEncoding, const std::string& toEncoding)
132 std::optional<std::string> res;
134 res = IconvString(value.value(), fromEncoding, toEncoding);