refactor(Core/Misc): Rewrite name handling functions that use raw buffers (#2230)

This commit is contained in:
Viste
2019-08-26 22:12:19 +03:00
committed by Francesco Borzì
parent 0b88e24808
commit bc1ad036a5
2 changed files with 41 additions and 44 deletions

View File

@@ -123,24 +123,15 @@ bool normalizePlayerName(std::string& name)
if (name.empty())
return false;
wchar_t wstr_buf[MAX_INTERNAL_PLAYER_NAME+1];
size_t wstr_len = MAX_INTERNAL_PLAYER_NAME;
if (!Utf8toWStr(name, &wstr_buf[0], wstr_len))
std::wstring tmp;
if (!Utf8toWStr(name, tmp))
return false;
wstr_buf[0] = wcharToUpper(wstr_buf[0]);
for (size_t i = 1; i < wstr_len; ++i)
wstr_buf[i] = wcharToLower(wstr_buf[i]);
wstrToLower(tmp);
if (!tmp.empty())
tmp[0] = wcharToUpper(tmp[0]);
// if there's "gm" at the end, uppercase it!
if (wstr_len>=2 && wstr_buf[wstr_len-2]==L'g' && wstr_buf[wstr_len-1]==L'm')
{
wstr_buf[wstr_len-2]=L'G';
wstr_buf[wstr_len-1]=L'M';
}
if (!WStrToUtf8(wstr_buf, wstr_len, name))
if (!WStrToUtf8(tmp, name))
return false;
return true;