[PATCH] msvcrt: implement _ismbclegal.
David Hedberg
david.hedberg at gmail.com
Sat Feb 20 01:17:19 CST 2010
---
dlls/msvcrt/mbcs.c | 49 ++++++++++++++++++++++++++++
dlls/msvcrt/msvcrt.spec | 2 +-
dlls/msvcrt/tests/string.c | 76 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 126 insertions(+), 1 deletions(-)
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index f738bcf..c7e00c3 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -1105,6 +1105,55 @@ int CDECL _ismbcpunct(unsigned int ch)
}
/*********************************************************************
+ * _ismbclegal(MSVCRT.@)
+ */
+int CDECL _ismbclegal(unsigned int c)
+{
+ /* Japanese */
+ if(MSVCRT___lc_codepage == 932)
+ {
+ if(((HIBYTE(c) >= 0x81 && HIBYTE(c) <= 0x9F) ||
+ (HIBYTE(c) >= 0xE0 && HIBYTE(c) <= 0xFC)) &&
+ ((LOBYTE(c) >= 0x40 && LOBYTE(c) <= 0x7E) ||
+ (LOBYTE(c) >= 0x80 && LOBYTE(c) <= 0xFC)))
+ return 1;
+ }
+ /* Chinese (GBK) */
+ if(MSVCRT___lc_codepage == 936)
+ {
+ if(HIBYTE(c) >= 0x81 && HIBYTE(c) <= 0xFE &&
+ LOBYTE(c) >= 0x40 && LOBYTE(c) <= 0xFE)
+ return 1;
+ }
+ /* Korean */
+ if(MSVCRT___lc_codepage == 949)
+ {
+ if(HIBYTE(c) >= 0x81 && HIBYTE(c) <= 0xFE &&
+ LOBYTE(c) >= 0x41 && LOBYTE(c) <= 0xFE)
+ return 1;
+ }
+ /* Chinese (Big5) */
+ if(MSVCRT___lc_codepage == 950)
+ {
+ if(HIBYTE(c) >= 0x81 && HIBYTE(c) <= 0xFE &&
+ ((LOBYTE(c) >= 0x40 && LOBYTE(c) <= 0x7E) ||
+ (LOBYTE(c) >= 0xA1 && LOBYTE(c) <= 0xFE)))
+ return 1;
+ }
+ /* Korean (Johab) */
+ if(MSVCRT___lc_codepage == 1361)
+ {
+ if(((HIBYTE(c) >= 0x81 && HIBYTE(c) <= 0xD3) ||
+ (HIBYTE(c) >= 0xD8 && HIBYTE(c) <= 0xF9)) &&
+ ((LOBYTE(c) >= 0x31 && LOBYTE(c) <= 0x7E) ||
+ (LOBYTE(c) >= 0x81 && LOBYTE(c) <= 0xFE)) &&
+ HIBYTE(c) != 0xDF)
+ return 1;
+ }
+ return 0;
+}
+
+/*********************************************************************
* _ismbchira(MSVCRT.@)
*/
int CDECL _ismbchira(unsigned int c)
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 51cb7df..a3bbb88 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 8544735..e776fc3 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -707,6 +707,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;
+ }
+ }
+ 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;
@@ -833,6 +908,7 @@ START_TEST(string)
test_strcat_s();
test__mbsnbcpy_s();
test_mbcjisjms();
+ test_ismbclegal();
test_strtok();
test_wcscpy_s();
test__wcsupr_s();
--
1.7.0
More information about the wine-patches
mailing list