Commit 578d85f3 authored by Akihiro Sagawa's avatar Akihiro Sagawa Committed by Alexandre Julliard

msvcrt: Improve _mbbtombc to handle Japanese characters.

parent d3e96650
...@@ -52,6 +52,19 @@ static struct cp_extra_info_t g_cpextrainfo[] = ...@@ -52,6 +52,19 @@ static struct cp_extra_info_t g_cpextrainfo[] =
{0, {1, 255, 0, 0}} /* match all with FIXME */ {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 */ /* Maps multibyte cp932 punctuation marks to single byte equivalents */
static const unsigned char mbctombb_932_punct[] = { static const unsigned char mbctombb_932_punct[] = {
0x20,0xa4,0xa1,0x2c,0x2e,0xa5,0x3a,0x3b,0x3f,0x21,0xde,0xdf,0x00,0x00,0x00,0x5e, 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) ...@@ -1080,14 +1093,22 @@ unsigned char* CDECL _mbstok(unsigned char *str, const unsigned char *delim)
*/ */
unsigned int CDECL _mbbtombc(unsigned int c) unsigned int CDECL _mbbtombc(unsigned int c)
{ {
if(get_mbcinfo()->ismbcodepage && if(get_mbcinfo()->mbcodepage == 932)
((c >= 0x20 && c <=0x7e) ||(c >= 0xa1 && c <= 0xdf)))
{ {
/* FIXME: I can't get this function to return anything if(c >= 0x20 && c <= 0x7e) {
* different from what I pass it... 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 */
} }
/********************************************************************* /*********************************************************************
......
...@@ -927,10 +927,6 @@ static void test_mbbtombc(void) ...@@ -927,10 +927,6 @@ static void test_mbbtombc(void)
unsigned int exp, ret; unsigned int exp, ret;
ret = _mbbtombc(mbbmbc[j][0]); ret = _mbbtombc(mbbmbc[j][0]);
exp = (cp[i] == 932) ? mbbmbc[j][1] : 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", ok(ret == exp, "Expected 0x%x, got 0x%x (0x%x, codepage %d)\n",
exp, ret, mbbmbc[j][0], cp[i]); exp, ret, mbbmbc[j][0], cp[i]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment