add utf8.escape, string.escape & reformat extensions.md

This commit is contained in:
MihailRis
2024-11-18 09:21:16 +03:00
parent 618a9f0411
commit dcd8871ee1
7 changed files with 85 additions and 44 deletions
+6
View File
@@ -94,6 +94,11 @@ static int l_encode(lua::State* L) {
return lua::pushlstring(L, bytes, count);
}
static int l_escape(lua::State* L) {
auto string = lua::require_lstring(L, 1);
return lua::pushstring(L, util::escape(string));
}
const luaL_Reg utf8lib[] = {
{"tobytes", lua::wrap<l_tobytes>},
{"tostring", lua::wrap<l_tostring>},
@@ -103,5 +108,6 @@ const luaL_Reg utf8lib[] = {
{"upper", lua::wrap<l_upper>},
{"lower", lua::wrap<l_lower>},
{"encode", lua::wrap<l_encode>},
{"escape", lua::wrap<l_escape>},
{NULL, NULL}
};
+1 -2
View File
@@ -7,8 +7,7 @@
#include <sstream>
#include <stdexcept>
// TODO: finish
std::string util::escape(const std::string& s) {
std::string util::escape(std::string_view s) {
std::stringstream ss;
ss << '"';
size_t pos = 0;
+1 -1
View File
@@ -8,7 +8,7 @@
namespace util {
/// @brief Function used for string serialization in text formats
std::string escape(const std::string& s);
std::string escape(std::string_view s);
/// @brief Function used for error messages
std::string quote(const std::string& s);