tlx
Loading...
Searching...
No Matches
escape_html.cpp
Go to the documentation of this file.
1
/*******************************************************************************
2
* tlx/string/escape_html.cpp
3
*
4
* Part of tlx - http://panthema.net/tlx
5
*
6
* Copyright (C) 2007-2017 Timo Bingmann <tb@panthema.net>
7
*
8
* All rights reserved. Published under the Boost Software License, Version 1.0
9
******************************************************************************/
10
11
#include <
tlx/string/escape_html.hpp
>
12
13
#include <cstring>
14
15
namespace
tlx
{
16
17
std::string
escape_html
(
const
std::string& str) {
18
std::string os;
19
os.reserve(str.size() + str.size() / 16);
20
21
for
(std::string::const_iterator si = str.begin(); si != str.end(); ++si)
22
{
23
if
(*si ==
'&'
) os +=
"&"
;
24
else
if
(*si ==
'<'
) os +=
"<"
;
25
else
if
(*si ==
'>'
) os +=
">"
;
26
else
if
(*si ==
'"'
) os +=
"""
;
27
else
os += *si;
28
}
29
30
return
os;
31
}
32
33
std::string
escape_html
(
const
char
* str) {
34
size_t
slen = strlen(str);
35
std::string os;
36
os.reserve(slen + slen / 16);
37
38
for
(
const
char
* si = str; *si != 0; ++si)
39
{
40
if
(*si ==
'&'
) os +=
"&"
;
41
else
if
(*si ==
'<'
) os +=
"<"
;
42
else
if
(*si ==
'>'
) os +=
">"
;
43
else
if
(*si ==
'"'
) os +=
"""
;
44
else
os += *si;
45
}
46
47
return
os;
48
}
49
50
}
// namespace tlx
51
52
/******************************************************************************/
escape_html.hpp
tlx::escape_html
std::string escape_html(const std::string &str)
Escape characters for inclusion in HTML documents: replaces the characters <, >, & and " with HTML en...
Definition
escape_html.cpp:17
tlx
Definition
exclusive_scan.hpp:17
tlx
string
escape_html.cpp
Generated on Sun Jan 19 2025 00:00:00 for tlx by
1.13.2