mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
use en_US.UTF-8 locale in utf8.tolower, toupper functions
This commit is contained in:
parent
3147897709
commit
36959807bd
2 changed files with 20 additions and 16 deletions
|
|
@ -66,19 +66,13 @@ static int l_sub(lua::State* L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_upper(lua::State* L) {
|
static int l_upper(lua::State* L) {
|
||||||
auto string = util::str2u32str_utf8(lua::require_string(L, 1));
|
auto string = util::str2wstr_utf8(lua::require_string(L, 1));
|
||||||
for (auto& c : string) {
|
return lua::pushwstring(L, util::upper_case(string));
|
||||||
c = std::towupper(c);
|
|
||||||
}
|
|
||||||
return lua::pushstring(L, util::u32str2str_utf8(string));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_lower(lua::State* L) {
|
static int l_lower(lua::State* L) {
|
||||||
auto string = util::str2u32str_utf8(lua::require_string(L, 1));
|
auto string = util::str2wstr_utf8(lua::require_string(L, 1));
|
||||||
for (auto& c : string) {
|
return lua::pushwstring(L, util::lower_case(string));
|
||||||
c = std::towlower(c);
|
|
||||||
}
|
|
||||||
return lua::pushstring(L, util::u32str2str_utf8(string));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l_encode(lua::State* L) {
|
static int l_encode(lua::State* L) {
|
||||||
|
|
|
||||||
|
|
@ -507,22 +507,32 @@ double util::parse_double(const std::string& str, size_t offset, size_t len) {
|
||||||
return parse_double(str.substr(offset, len));
|
return parse_double(str.substr(offset, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring util::lower_case(const std::wstring& str) {
|
template<typename CharT>
|
||||||
std::wstring result = str;
|
static std::basic_string<CharT> lower_case(const std::basic_string<CharT>& str) {
|
||||||
|
std::basic_string<CharT> result = str;
|
||||||
for (uint i = 0; i < result.length(); i++) {
|
for (uint i = 0; i < result.length(); i++) {
|
||||||
result[i] = static_cast<wchar_t>(std::tolower(str[i], locale));
|
result[i] = std::tolower(str[i], locale);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring util::upper_case(const std::wstring& str) {
|
template<typename CharT>
|
||||||
std::wstring result = str;
|
static std::basic_string<CharT> upper_case(const std::basic_string<CharT>& str) {
|
||||||
|
std::basic_string<CharT> result = str;
|
||||||
for (uint i = 0; i < result.length(); i++) {
|
for (uint i = 0; i < result.length(); i++) {
|
||||||
result[i] = static_cast<wchar_t>(std::toupper(str[i], locale));
|
result[i] = std::toupper(str[i], locale);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wstring util::lower_case(const std::wstring& str) {
|
||||||
|
return ::lower_case(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring util::upper_case(const std::wstring& str) {
|
||||||
|
return ::upper_case(str);
|
||||||
|
}
|
||||||
|
|
||||||
std::wstring util::capitalized(const std::wstring& str) {
|
std::wstring util::capitalized(const std::wstring& str) {
|
||||||
if (str.empty()) return str;
|
if (str.empty()) return str;
|
||||||
return std::wstring({static_cast<wchar_t>(std::toupper(str[0], locale))}) +
|
return std::wstring({static_cast<wchar_t>(std::toupper(str[0], locale))}) +
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue