mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 20:11:50 +00:00
add utf8.escape, string.escape & reformat extensions.md
This commit is contained in:
parent
618a9f0411
commit
dcd8871ee1
7 changed files with 85 additions and 44 deletions
|
|
@ -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}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue