mirror of
https://github.com/holub/mame
synced 2025-04-22 08:22:15 +03:00
osd: Added multibyte check to osd_uchar_from_osdchar to fix decoding ASCII text. (#9536)
This allows ASCII INI files to be parsed on Windows systems set to use a double-byte code page. It should also work with correctly-encoded Shift-JIS, GB2312, Big5 and EUC-KR. It won’t work for more complex variable-length encodings, or when the input is not correctly encoded.
This commit is contained in:
parent
ec3cd170e7
commit
c161f61973
@ -254,6 +254,11 @@ std::string from_wstring(const WCHAR *s)
|
||||
|
||||
int osd_uchar_from_osdchar(char32_t *uchar, const char *osdchar, size_t count)
|
||||
{
|
||||
// FIXME: Does not handle charsets that use variable lengths encodings such
|
||||
// as example GB18030 or UTF-8.
|
||||
// FIXME: Assumes all characters can be converted into a single wchar_t
|
||||
// which may not always be the case such as with surrogate pairs.
|
||||
|
||||
WCHAR wch;
|
||||
CPINFO cp;
|
||||
|
||||
@ -261,7 +266,7 @@ int osd_uchar_from_osdchar(char32_t *uchar, const char *osdchar, size_t count)
|
||||
goto error;
|
||||
|
||||
// The multibyte char can't be bigger than the max character size
|
||||
count = std::min(count, size_t(cp.MaxCharSize));
|
||||
count = std::min(count, size_t(IsDBCSLeadByte(*osdchar) ? cp.MaxCharSize : 1));
|
||||
|
||||
if (MultiByteToWideChar(CP_ACP, 0, osdchar, static_cast<DWORD>(count), &wch, 1) == 0)
|
||||
goto error;
|
||||
|
Loading…
Reference in New Issue
Block a user