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