From 30f6dc9510033dec4782ac00a53a0bc00a18b63d Mon Sep 17 00:00:00 2001 From: David Hedberg Date: Tue, 23 Feb 2010 07:05:44 +0100 Subject: [PATCH] msvcrt: Implement _ismbclegal. --- dlls/msvcrt/mbcs.c | 8 ++++ dlls/msvcrt/msvcrt.spec | 2 +- dlls/msvcrt/tests/string.c | 76 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index f4bb248fa6..38891e625d 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -1152,6 +1152,14 @@ int CDECL _ismbbtrail(unsigned int c) return (MSVCRT_mbctype[(c&0xff) + 1] & _M2) != 0; } +/********************************************************************* + * _ismbclegal(MSVCRT.@) + */ +int CDECL _ismbclegal(unsigned int c) +{ + return _ismbblead(HIBYTE(c)) && _ismbbtrail(LOBYTE(c)); +} + /********************************************************************* * _ismbslead(MSVCRT.@) */ diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec index 51cb7df446..a3bbb88fc8 100644 --- a/dlls/msvcrt/msvcrt.spec +++ b/dlls/msvcrt/msvcrt.spec @@ -336,7 +336,7 @@ @ stub _ismbcl0 #(long) @ stub _ismbcl1 #(long) @ stub _ismbcl2 #(long) -@ stub _ismbclegal #(long) +@ cdecl _ismbclegal(long) @ cdecl _ismbclower(long) @ cdecl _ismbcprint(long) @ cdecl _ismbcpunct(long) diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 182c598cf0..199c0fad96 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -730,6 +730,81 @@ static void test_mbcjisjms(void) } while(jisjms[i++][0] != 0); } +static void test_ismbclegal(void) { + unsigned int prev_cp = _getmbcp(); + int ret, exp, err; + unsigned int i; + + _setmbcp(932); /* Japanese */ + err = 0; + for(i = 0; i < 0x10000; i++) { + ret = _ismbclegal(i); + exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0x9F) || + (HIBYTE(i) >= 0xE0 && HIBYTE(i) <= 0xFC)) && + ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) || + (LOBYTE(i) >= 0x80 && LOBYTE(i) <= 0xFC)); + if(ret != exp) { + err = 1; + break; + } + } + ok(!err, "_ismbclegal (932) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i); + _setmbcp(936); /* Chinese (GBK) */ + err = 0; + for(i = 0; i < 0x10000; i++) { + ret = _ismbclegal(i); + exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE && + LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0xFE; + if(ret != exp) { + err = 1; + break; + } + } + ok(!err, "_ismbclegal (936) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i); + _setmbcp(949); /* Korean */ + err = 0; + for(i = 0; i < 0x10000; i++) { + ret = _ismbclegal(i); + exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE && + LOBYTE(i) >= 0x41 && LOBYTE(i) <= 0xFE; + if(ret != exp) { + err = 1; + break; + } + } + ok(!err, "_ismbclegal (949) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i); + _setmbcp(950); /* Chinese (Big5) */ + err = 0; + for(i = 0; i < 0x10000; i++) { + ret = _ismbclegal(i); + exp = HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xFE && + ((LOBYTE(i) >= 0x40 && LOBYTE(i) <= 0x7E) || + (LOBYTE(i) >= 0xA1 && LOBYTE(i) <= 0xFE)); + if(ret != exp) { + err = 1; + break; + } + } + ok(!err, "_ismbclegal (950) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i); + _setmbcp(1361); /* Korean (Johab) */ + err = 0; + for(i = 0; i < 0x10000; i++) { + ret = _ismbclegal(i); + exp = ((HIBYTE(i) >= 0x81 && HIBYTE(i) <= 0xD3) || + (HIBYTE(i) >= 0xD8 && HIBYTE(i) <= 0xF9)) && + ((LOBYTE(i) >= 0x31 && LOBYTE(i) <= 0x7E) || + (LOBYTE(i) >= 0x81 && LOBYTE(i) <= 0xFE)) && + HIBYTE(i) != 0xDF; + if(ret != exp) { + err = 1; + break; + } + } + todo_wine ok(!err, "_ismbclegal (1361) : Expected 0x%x, got 0x%x (0x%x)\n", exp, ret, i); + + _setmbcp(prev_cp); +} + static const struct { const char* string; const char* delimiter; @@ -856,6 +931,7 @@ START_TEST(string) test_strcat_s(); test__mbsnbcpy_s(); test_mbcjisjms(); + test_ismbclegal(); test_strtok(); test_wcscpy_s(); test__wcsupr_s(); -- 2.32.0.93.g670b81a890