Skip to content

Commit 23c6d0c

Browse files
author
Maksim
authoredApr 17, 2020
Android: fix handling non-latin characters on older Android devices (#9309)
1 parent 4e2473e commit 23c6d0c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

Diff for: ‎src/server.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -3031,8 +3031,16 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
30313031
line += L"-!- You don't have permission to shout.";
30323032
broadcast_line = false;
30333033
} else {
3034+
/*
3035+
Workaround for fixing chat on Android. Lua doesn't handle
3036+
the Cyrillic alphabet and some characters on older Android devices
3037+
*/
3038+
#ifdef __ANDROID__
3039+
line += L"<" + wname + L"> " + wmessage;
3040+
#else
30343041
line += narrow_to_wide(m_script->formatChatMessage(name,
30353042
wide_to_narrow(wmessage)));
3043+
#endif
30363044
}
30373045

30383046
/*

Diff for: ‎src/util/string.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,25 @@ wchar_t *narrow_to_wide_c(const char *str)
209209
}
210210

211211
std::wstring narrow_to_wide(const std::string &mbs) {
212+
#ifdef __ANDROID__
213+
return utf8_to_wide(mbs);
214+
#else
212215
size_t wcl = mbs.size();
213216
Buffer<wchar_t> wcs(wcl + 1);
214217
size_t len = mbstowcs(*wcs, mbs.c_str(), wcl);
215218
if (len == (size_t)(-1))
216219
return L"<invalid multibyte string>";
217220
wcs[len] = 0;
218221
return *wcs;
222+
#endif
219223
}
220224

221225

222226
std::string wide_to_narrow(const std::wstring &wcs)
223227
{
228+
#ifdef __ANDROID__
229+
return wide_to_utf8(wcs);
230+
#else
224231
size_t mbl = wcs.size() * 4;
225232
SharedBuffer<char> mbs(mbl+1);
226233
size_t len = wcstombs(*mbs, wcs.c_str(), mbl);
@@ -229,6 +236,7 @@ std::string wide_to_narrow(const std::wstring &wcs)
229236

230237
mbs[len] = 0;
231238
return *mbs;
239+
#endif
232240
}
233241

234242

0 commit comments

Comments
 (0)
Please sign in to comment.