Module: wine Branch: master Commit: a6a8a034bda35f88848e6b0f03f3c070d27bab55 URL: https://source.winehq.org/git/wine.git/?a=commit;h=a6a8a034bda35f88848e6b0f0...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Tue Mar 12 13:12:24 2019 +0300
imm32: Get rid of some casts in attributes helper, document arguments.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Aric Stewart aric@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/imm32/imm.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/dlls/imm32/imm.c b/dlls/imm32/imm.c index 948ef78..b462141 100644 --- a/dlls/imm32/imm.c +++ b/dlls/imm32/imm.c @@ -1231,33 +1231,40 @@ static INT CopyCompStringIMEtoClient(const InputContextData *data, const void *s return ret; }
-static INT CopyCompAttrIMEtoClient(InputContextData *data, LPBYTE source, INT slen, LPBYTE ssource, INT sslen, - LPBYTE target, INT tlen, BOOL unicode ) +/* Composition string encoding is defined by context, returned attributes correspond to string, converted according to + passed mode. String length is in characters, attributes are in byte arrays. */ +static INT CopyCompAttrIMEtoClient(const InputContextData *data, const BYTE *src, INT src_len, const void *comp_string, + INT str_len, BYTE *dst, INT dst_len, BOOL unicode) { + union + { + const void *str; + const WCHAR *strW; + const char *strA; + } string; INT rc;
+ string.str = comp_string; + if (is_himc_ime_unicode(data) && !unicode) { - rc = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)ssource, sslen, NULL, 0, NULL, NULL); - if (tlen) + rc = WideCharToMultiByte(CP_ACP, 0, string.strW, str_len, NULL, 0, NULL, NULL); + if (dst_len) { - const BYTE *src = source; - LPBYTE dst = target; int i, j = 0, k = 0;
- if (rc < tlen) - tlen = rc; - for (i = 0; i < sslen; ++i) + if (rc < dst_len) + dst_len = rc; + for (i = 0; i < str_len; ++i) { int len;
- len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)ssource + i, 1, - NULL, 0, NULL, NULL); + len = WideCharToMultiByte(CP_ACP, 0, string.strW + i, 1, NULL, 0, NULL, NULL); for (; len > 0; --len) { dst[j++] = src[k];
- if (j >= tlen) + if (j >= dst_len) goto end; } ++k; @@ -1268,23 +1275,21 @@ static INT CopyCompAttrIMEtoClient(InputContextData *data, LPBYTE source, INT sl } else if (!is_himc_ime_unicode(data) && unicode) { - rc = MultiByteToWideChar(CP_ACP, 0, (LPSTR)ssource, sslen, NULL, 0); - if (tlen) + rc = MultiByteToWideChar(CP_ACP, 0, string.strA, str_len, NULL, 0); + if (dst_len) { - const BYTE *src = source; - LPBYTE dst = target; int i, j = 0;
- if (rc < tlen) - tlen = rc; - for (i = 0; i < sslen; ++i) + if (rc < dst_len) + dst_len = rc; + for (i = 0; i < str_len; ++i) { - if (IsDBCSLeadByte(((LPSTR)ssource)[i])) + if (IsDBCSLeadByte(string.strA[i])) continue;
dst[j++] = src[i];
- if (j >= tlen) + if (j >= dst_len) break; } rc = j; @@ -1292,8 +1297,8 @@ static INT CopyCompAttrIMEtoClient(InputContextData *data, LPBYTE source, INT sl } else { - memcpy( target, source, min(slen,tlen)); - rc = slen; + memcpy(dst, src, min(src_len, dst_len)); + rc = src_len; }
return rc;