fix utf8 support
This commit is contained in:
parent
6810f9a03a
commit
28589c4b3b
@ -89,8 +89,8 @@ static int l_escape(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_escape_xml(lua::State* L) {
|
||||
auto string = lua::require_lstring(L, 1);
|
||||
return lua::pushstring(L, util::escape_xml(string));
|
||||
auto string = lua::require_wstring(L, 1);
|
||||
return lua::pushwstring(L, util::escape_xml(string));
|
||||
}
|
||||
|
||||
const luaL_Reg utf8lib[] = {
|
||||
|
||||
@ -60,24 +60,24 @@ 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) {
|
||||
std::wstring util::escape_xml(std::wstring_view s) {
|
||||
std::wstringstream ss;
|
||||
for (wchar_t c : s) {
|
||||
switch (c) {
|
||||
case '&':
|
||||
ss << "&";
|
||||
case L'&':
|
||||
ss << L"&";
|
||||
break;
|
||||
case '<':
|
||||
ss << "<";
|
||||
case L'<':
|
||||
ss << L"<";
|
||||
break;
|
||||
case '>':
|
||||
ss << ">";
|
||||
case L'>':
|
||||
ss << L">";
|
||||
break;
|
||||
case '"':
|
||||
ss << """;
|
||||
ss << L""";
|
||||
break;
|
||||
case '\'':
|
||||
ss << "'";
|
||||
ss << L"'";
|
||||
break;
|
||||
default:
|
||||
ss << c;
|
||||
|
||||
@ -11,7 +11,7 @@ namespace util {
|
||||
std::string escape(std::string_view s, bool escapeUnicode=true);
|
||||
|
||||
/// @brief Escape all special XML characters
|
||||
std::string escape_xml(std::string_view s);
|
||||
std::wstring escape_xml(std::wstring_view s);
|
||||
|
||||
/// @brief Function used for error messages
|
||||
std::string quote(const std::string& s);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user