mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add utf8.escape_xml and alias - string.escape_xml
This commit is contained in:
parent
91cb5ab7d8
commit
6810f9a03a
4 changed files with 37 additions and 0 deletions
|
|
@ -60,6 +60,33 @@ std::string util::escape(std::string_view s, bool escapeUnicode) {
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
std::string util::escape_xml(std::string_view s) {
|
||||
std::stringstream ss;
|
||||
for (char c : s) {
|
||||
switch (c) {
|
||||
case '&':
|
||||
ss << "&";
|
||||
break;
|
||||
case '<':
|
||||
ss << "<";
|
||||
break;
|
||||
case '>':
|
||||
ss << ">";
|
||||
break;
|
||||
case '"':
|
||||
ss << """;
|
||||
break;
|
||||
case '\'':
|
||||
ss << "'";
|
||||
break;
|
||||
default:
|
||||
ss << c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string util::quote(const std::string& s) {
|
||||
return escape(s, false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue