mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Android: fix handling non-latin characters on older Android devices (#9309)
This commit is contained in:
parent
4e2473ec49
commit
23c6d0c31f
2 changed files with 16 additions and 0 deletions
|
@ -209,6 +209,9 @@ wchar_t *narrow_to_wide_c(const char *str)
|
|||
}
|
||||
|
||||
std::wstring narrow_to_wide(const std::string &mbs) {
|
||||
#ifdef __ANDROID__
|
||||
return utf8_to_wide(mbs);
|
||||
#else
|
||||
size_t wcl = mbs.size();
|
||||
Buffer<wchar_t> wcs(wcl + 1);
|
||||
size_t len = mbstowcs(*wcs, mbs.c_str(), wcl);
|
||||
|
@ -216,11 +219,15 @@ std::wstring narrow_to_wide(const std::string &mbs) {
|
|||
return L"<invalid multibyte string>";
|
||||
wcs[len] = 0;
|
||||
return *wcs;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string wide_to_narrow(const std::wstring &wcs)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
return wide_to_utf8(wcs);
|
||||
#else
|
||||
size_t mbl = wcs.size() * 4;
|
||||
SharedBuffer<char> mbs(mbl+1);
|
||||
size_t len = wcstombs(*mbs, wcs.c_str(), mbl);
|
||||
|
@ -229,6 +236,7 @@ std::string wide_to_narrow(const std::wstring &wcs)
|
|||
|
||||
mbs[len] = 0;
|
||||
return *mbs;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue