mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-11 08:52:06 +00:00
add function to escape charaters for HTML
This commit is contained in:
parent
c0489ce537
commit
eb0c442763
@ -581,6 +581,59 @@ void writeCSVString(const StringRef & s, WriteBuffer & buf)
|
||||
writeCSVString<quote>(s.data, s.data + s.size, buf);
|
||||
}
|
||||
|
||||
inline void writeHTMLString(const char * begin, const char * end, WriteBuffer & buf)
|
||||
{
|
||||
const char * pos = begin;
|
||||
while (true)
|
||||
{
|
||||
const char * next_pos = find_first_symbols<'<', '&', '>', '"', '\''>(pos, end);
|
||||
|
||||
if (next_pos == end)
|
||||
{
|
||||
buf.write(pos, end - pos);
|
||||
break;
|
||||
}
|
||||
else if (*next_pos == '<')
|
||||
{
|
||||
buf.write(pos, next_pos - pos);
|
||||
++next_pos;
|
||||
writeCString("<", buf);
|
||||
}
|
||||
else if (*next_pos == '&')
|
||||
{
|
||||
buf.write(pos, next_pos - pos);
|
||||
++next_pos;
|
||||
writeCString("&", buf);
|
||||
}else if (*next_pos == '>')
|
||||
{
|
||||
buf.write(pos, next_pos - pos);
|
||||
++next_pos;
|
||||
writeCString(">", buf);
|
||||
}else if (*next_pos == '"')
|
||||
{
|
||||
buf.write(pos, next_pos - pos);
|
||||
++next_pos;
|
||||
writeCString(""", buf);
|
||||
}else if (*next_pos == '\'')
|
||||
{
|
||||
buf.write(pos, next_pos - pos);
|
||||
++next_pos;
|
||||
writeCString("'", buf);
|
||||
}
|
||||
|
||||
pos = next_pos;
|
||||
}
|
||||
}
|
||||
|
||||
inline void writeHTMLString(const String & s, WriteBuffer & buf)
|
||||
{
|
||||
writeHTMLString(s.data(), s.data() + s.size(), buf);
|
||||
}
|
||||
|
||||
inline void writeHTMLString(const StringRef & s, WriteBuffer & buf)
|
||||
{
|
||||
writeHTMLString(s.data, s.data + s.size, buf);
|
||||
}
|
||||
|
||||
/// Writing a string to a text node in XML (not into an attribute - otherwise you need more escaping).
|
||||
inline void writeXMLString(const char * begin, const char * end, WriteBuffer & buf)
|
||||
|
Loading…
Reference in New Issue
Block a user