diff options
author | 987123879113 <63495610+987123879113@users.noreply.github.com> | 2022-04-10 01:48:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-10 02:48:27 +1000 |
commit | c161f6197369f71515d0f383771be913b88e6a78 (patch) | |
tree | 7916cde439263cbeae91cd9dade0863f5788295d /src/osd | |
parent | ec3cd170e74a1d1eacc52536e4568f0797e4648a (diff) |
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.
Diffstat (limited to 'src/osd')
-rw-r--r-- | src/osd/strconv.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/osd/strconv.cpp b/src/osd/strconv.cpp index 4dafeddd398..737cb9fc1dc 100644 --- a/src/osd/strconv.cpp +++ b/src/osd/strconv.cpp @@ -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; |