add utf8.upper, utf8.lower

This commit is contained in:
MihailRis
2024-10-27 21:32:30 +03:00
parent 699d8ce2bb
commit 3e86d49a7b
3 changed files with 30 additions and 0 deletions
+18
View File
@@ -63,11 +63,29 @@ static int l_sub(lua::State* L) {
return lua::pushstring(L, util::u32str2str_utf8(string.substr(start, end)));
}
static int l_upper(lua::State* L) {
auto string = util::str2u32str_utf8(lua::require_string(L, 1));
for (auto& c : string) {
c = std::towupper(c);
}
return lua::pushstring(L, util::u32str2str_utf8(string));
}
static int l_lower(lua::State* L) {
auto string = util::str2u32str_utf8(lua::require_string(L, 1));
for (auto& c : string) {
c = std::towlower(c);
}
return lua::pushstring(L, util::u32str2str_utf8(string));
}
const luaL_Reg utf8lib[] = {
{"tobytes", lua::wrap<l_encode>},
{"tostring", lua::wrap<l_decode>},
{"length", lua::wrap<l_length>},
{"codepoint", lua::wrap<l_codepoint>},
{"sub", lua::wrap<l_sub>},
{"upper", lua::wrap<l_upper>},
{"lower", lua::wrap<l_lower>},
{NULL, NULL}
};