mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Merge pull request #833 from MihailRis/fix-another-locale-issue
use en_US.UTF-8 locale in utf8.tolower, toupper functions
This commit is contained in:
commit
2db80051fd
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) {
|
||||
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));
|
||||
auto string = util::str2wstr_utf8(lua::require_string(L, 1));
|
||||
return lua::pushwstring(L, util::upper_case(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));
|
||||
auto string = util::str2wstr_utf8(lua::require_string(L, 1));
|
||||
return lua::pushwstring(L, util::lower_case(string));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
std::wstring util::lower_case(const std::wstring& str) {
|
||||
std::wstring result = str;
|
||||
template<typename CharT>
|
||||
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++) {
|
||||
result[i] = static_cast<wchar_t>(std::tolower(str[i], locale));
|
||||
result[i] = std::tolower(str[i], locale);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring util::upper_case(const std::wstring& str) {
|
||||
std::wstring result = str;
|
||||
template<typename CharT>
|
||||
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++) {
|
||||
result[i] = static_cast<wchar_t>(std::toupper(str[i], locale));
|
||||
result[i] = std::toupper(str[i], locale);
|
||||
}
|
||||
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) {
|
||||
if (str.empty()) return str;
|
||||
return std::wstring({static_cast<wchar_t>(std::toupper(str[0], locale))}) +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue