forked from jaredtao/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHtmlWriter.h
40 lines (39 loc) · 893 Bytes
/
HtmlWriter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <sstream>
#include <string>
class HtmlWriter
{
public:
void title(const std::string &title)
{
m_ss << "<html>"
<< "<head>"
<< "<title>" + title + "</title>"
<< "</head>"
<< "<body>\n"
<< "<h1>" + title + "</h1>\n";
}
void paragraph(const std::string &msg)
{
m_ss << "<p>" + msg + "</p>\n";
}
void link(const std::string &herf, const std::string &caption)
{
paragraph("<a herf=\"" + herf + "\">" + caption + "</a>");
}
void mailto(const std::string &mailAddr, const std::string &userName)
{
link("mailto:" + mailAddr, userName);
}
void close()
{
m_ss << "</body>"
<< "</html>\n";
}
std::string toString() const
{
return m_ss.str();
}
private:
std::stringstream m_ss;
};