add utf8.upper, utf8.lower
This commit is contained in:
@@ -18,4 +18,10 @@ utf8.codepoint(chars: str) -> int
|
|||||||
|
|
||||||
-- Returns a substring from position startchar to endchar inclusive
|
-- Returns a substring from position startchar to endchar inclusive
|
||||||
utf8.sub(text: str, startchar: int, [optional] endchar: int) -> str
|
utf8.sub(text: str, startchar: int, [optional] endchar: int) -> str
|
||||||
|
|
||||||
|
-- Converts a string to uppercase
|
||||||
|
utf8.upper(text: str) -> str
|
||||||
|
|
||||||
|
-- Converts a string to lowercase
|
||||||
|
utf8.lower(text: str) -> str
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -18,4 +18,10 @@ utf8.codepoint(chars: str) -> int
|
|||||||
|
|
||||||
-- Возвращает подстроку от позиции startchar до endchar включительно
|
-- Возвращает подстроку от позиции startchar до endchar включительно
|
||||||
utf8.sub(text: str, startchar: int, [опционально] endchar: int) -> str
|
utf8.sub(text: str, startchar: int, [опционально] endchar: int) -> str
|
||||||
|
|
||||||
|
-- Переводит строку в вверхний регистр
|
||||||
|
utf8.upper(text: str) -> str
|
||||||
|
|
||||||
|
-- Переводит строку в нижний регистр
|
||||||
|
utf8.lower(text: str) -> str
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -63,11 +63,29 @@ static int l_sub(lua::State* L) {
|
|||||||
return lua::pushstring(L, util::u32str2str_utf8(string.substr(start, end)));
|
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[] = {
|
const luaL_Reg utf8lib[] = {
|
||||||
{"tobytes", lua::wrap<l_encode>},
|
{"tobytes", lua::wrap<l_encode>},
|
||||||
{"tostring", lua::wrap<l_decode>},
|
{"tostring", lua::wrap<l_decode>},
|
||||||
{"length", lua::wrap<l_length>},
|
{"length", lua::wrap<l_length>},
|
||||||
{"codepoint", lua::wrap<l_codepoint>},
|
{"codepoint", lua::wrap<l_codepoint>},
|
||||||
{"sub", lua::wrap<l_sub>},
|
{"sub", lua::wrap<l_sub>},
|
||||||
|
{"upper", lua::wrap<l_upper>},
|
||||||
|
{"lower", lua::wrap<l_lower>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user