msvcrt[2/5]: implement _ismbblead/_ismbbtrail using _mbctype (with tests)

Mikolaj Zalewski mikolajz at google.com
Mon Aug 20 12:17:16 CDT 2007


On Windows the codepage set by _setmbcp is a different thing than the
one set by the locale. Before spliting them I wanted to test what
function uses which codepage. _ismbblead/_ismbbtrail uses mbcp.
-------------- next part --------------
From d2692c05567af54b07d213901131b1fd6028ec07 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Miko=C5=82aj_Zalewski?= <mikolaj at zalewski.pl>
Date: Sun, 19 Aug 2007 22:30:45 -0700
Subject: [PATCH] msvcrt: implement _ismbblead/_ismbbtrail using _mbctype (with tests)

---
 dlls/msvcrt/mbcs.c         |    6 ++----
 dlls/msvcrt/tests/string.c |    8 ++++++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index af184b2..fa1e207 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -1056,8 +1056,7 @@ int CDECL _ismbckata(unsigned int c)
  */
 int CDECL _ismbblead(unsigned int c)
 {
-  /* FIXME: should reference MSVCRT_mbctype */
-  return MSVCRT_isleadbyte(c);
+  return (MSVCRT_mbctype[(c&0xff) + 1] & _M1) != 0;
 }
 
 
@@ -1066,8 +1065,7 @@ int CDECL _ismbblead(unsigned int c)
  */
 int CDECL _ismbbtrail(unsigned int c)
 {
-  /* FIXME: should reference MSVCRT_mbctype */
-  return !_ismbblead(c);
+  return (MSVCRT_mbctype[(c&0xff) + 1] & _M2) != 0;
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index aa29703..6ac3fe2 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -161,7 +161,6 @@ void test_cp_table(int cp, int *result, int *todo)
 
 static void test_mbcp(void)
 {
-    unsigned int s = '\354';
     int mb_orig_max = __mb_cur_max;
     int curr_mbcp = _getmbcp();
 
@@ -177,7 +176,12 @@ static void test_mbcp(void)
 
     _setmbcp(936);
     ok(__mb_cur_max == mb_orig_max, "__mb_cur_max shouldn't be updated (is %d != %d)\n", __mb_cur_max, mb_orig_max);
-    todo_wine ok(_ismbblead(s), "got result %d\n", _ismbblead(s));
+    ok(_ismbblead('\354'), "\354 should be a lead byte\n");
+    ok(_ismbblead(' ') == FALSE, "' ' should not be a lead byte\n");
+    ok(_ismbblead(0x1234b0), "0x1234b0 should not be a lead byte\n");
+    ok(_ismbblead(0x123420) == FALSE, "0x123420 should not be a lead byte\n");
+    ok(_ismbbtrail('\xb0'), "\xa0 should be a trail byte\n");
+    ok(_ismbbtrail(' ') == FALSE, "' ' should not be a trail byte\n");
     _setmbcp(curr_mbcp);
 }
 
-- 
1.4.4.2


More information about the wine-patches mailing list