Module: wine Branch: master Commit: 578d85f320e04608200abd80440c2ff605461a7f URL: http://source.winehq.org/git/wine.git/?a=commit;h=578d85f320e04608200abd8044...
Author: Akihiro Sagawa sagawa.aki@gmail.com Date: Wed Mar 21 23:02:10 2012 +0900
msvcrt: Improve _mbbtombc to handle Japanese characters.
---
dlls/msvcrt/mbcs.c | 33 +++++++++++++++++++++++++++------ dlls/msvcrt/tests/string.c | 8 ++------ 2 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index 6d3e3fb..c61311b 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -52,6 +52,19 @@ static struct cp_extra_info_t g_cpextrainfo[] = {0, {1, 255, 0, 0}} /* match all with FIXME */ };
+/* Maps cp932 single byte character to multi byte character */ +static const unsigned char mbbtombc_932[] = { + 0x40,0x49,0x68,0x94,0x90,0x93,0x95,0x66,0x69,0x6a,0x96,0x7b,0x43,0x7c,0x44,0x5e, + 0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x46,0x47,0x83,0x81,0x84,0x48, + 0x97,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e, + 0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x76, + 0x77,0x78,0x79,0x6d,0x8f,0x6e,0x4f,0x51,0x65,0x81,0x82,0x83,0x84,0x85,0x86,0x87, + 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x50, + 0x42,0x75,0x76,0x41,0x45,0x92,0x40,0x42,0x44,0x46,0x48,0x83,0x85,0x87,0x62, + 0x5b,0x41,0x43,0x45,0x47,0x49,0x4a,0x4c,0x4e,0x50,0x52,0x54,0x56,0x58,0x5a,0x5c, + 0x5e,0x60,0x63,0x65,0x67,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x71,0x74,0x77,0x7a,0x7d, + 0x7e,0x80,0x81,0x82,0x84,0x86,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8f,0x93,0x4a,0x4b }; + /* Maps multibyte cp932 punctuation marks to single byte equivalents */ static const unsigned char mbctombb_932_punct[] = { 0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e, @@ -1080,14 +1093,22 @@ unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim) */ unsigned int CDECL _mbbtombc(unsigned int c) { - if(get_mbcinfo()->ismbcodepage && - ((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf))) + if(get_mbcinfo()->mbcodepage == 932) { - /* FIXME: I can't get this function to return anything - * different from what I pass it... - */ + if(c >= 0x20 && c <= 0x7e) { + if((c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a) || (c >= 0x30 && c <= 0x39)) + return mbbtombc_932[c - 0x20] | 0x8200; + else + return mbbtombc_932[c - 0x20] | 0x8100; + } + else if(c >= 0xa1 && c <= 0xdf) { + if(c >= 0xa6 && c <= 0xdd && c != 0xb0) + return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8300; + else + return mbbtombc_932[c - 0xa1 + 0x5f] | 0x8100; + } } - return c; /* ASCII CP or no MB char */ + return c; /* not Japanese or no MB char */ }
/********************************************************************* diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index e65b274..f3fb243 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -927,12 +927,8 @@ static void test_mbbtombc(void) unsigned int exp, ret; ret = _mbbtombc(mbbmbc[j][0]); exp = (cp[i] == 932) ? mbbmbc[j][1] : mbbmbc[j][0]; - if (cp[i] == 932 && exp > 255) - todo_wine ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n", - exp, ret, mbbmbc[j][0], cp[i]); - else - ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n", - exp, ret, mbbmbc[j][0], cp[i]); + ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n", + exp, ret, mbbmbc[j][0], cp[i]); } } _setmbcp(prev_cp);