On Tuesday 15 March 2005 00:43, Juan Lang wrote:
> Raphael wrote:
> > +  if (!*str) { /** TODO: check *str validity */
> > +    return -1; /** _MBC_ILLEGAL */
> > +  }
> > +  if (start == str && MSVCRT_isleadbyte(*str)) {
> > +    return 1; /** _MBC_LEAD */
> > +  }
> > +  if (start == str && MSVCRT_isleadbyte(str[-1])) {
> > +    return 2; /**_MBC_TRAIL */
> > +  }
> > +
> > +  return 0; /** _MBC_SINGLE */
>
> Cool.  How about patching mbctype.h with these constants too?
>
> --Juan

Try 2 :)

�Changelog:
� - implement _mbsbtype (bug 1831)


This One without tests improvements as they failed on wine (as wine don't seems 
to support chineese) :(

the test patch for people who want to test:
Index: dlls/msvcrt/tests/string.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/tests/string.c,v
retrieving revision 1.2
diff -u -r1.2 string.c
--- dlls/msvcrt/tests/string.c  4 May 2004 04:13:06 -0000       1.2
+++ dlls/msvcrt/tests/string.c  5 Apr 2005 20:33:36 -0000
@@ -22,6 +22,8 @@
 #include "winbase.h"
 #include <string.h>
 #include <stdlib.h>
+#include "mbctype.h"
+#include "mbstring.h"

 static void* (*pmemcpy)(void *, const void *, size_t n);
 static int* (*pmemcmp)(void *, const void *, size_t n);
@@ -34,6 +36,10 @@
 {
     void *mem;
     static const char xilstring[]="c:/xilinx";
+
+    static const char s_chin[] = "\326\354"; /* ZHU1 for mbcs tests */
+    static const char s_jap[] = "A\x9A\x8B\xE0\xEF\xF0xXyYzZ";
+
     int nLen=strlen(xilstring);
     HMODULE hMsvcrt = LoadLibraryA("msvcrt.dll");
     ok(hMsvcrt != 0, "LoadLibraryA failed\n");
@@ -46,6 +52,24 @@
     ok(mem != NULL, "memory not allocated for size 0\n");
     strcpy((char*)mem,xilstring);
     pmemcpy((char*)mem+5, mem,nLen+1);
-    ok(pmemcmp((char*)mem+5,xilstring, nLen) == 0,
-       "Got result %s\n",(char*)mem+5);
+    ok(pmemcmp((char*)mem+5,xilstring, nLen) == 0, "Got result 
%s\n",(char*)mem+5);
+
+    /**
+     * http://www.geocities.com/yongweiwu/multibyte.htm
+     * http://home.a03.itscom.net/tsuzu/programing/tips06_2.htm
+     */
+
+    _setmbcp(936); /* Japanese */
+    ok( 0 == _ismbblead(s_jap[1]), "0 == _ismbblead(s_jap[1]), was %d\n",  
_ismbblead(s_jap[1]) );
+
+    _setmbcp(932); /* Chinese GBK */
+    ok( 4 == _ismbblead(s_chin[1]),     "4 == _ismbblead(s_chin[1]), was 
%d\n",  _ismbblead(s_chin[1]) );
+    ok( 0 == _ismbslead(s_chin, &s_chin[1]), "0 == _ismbslead(s_chin, 
&s_chin[1]), was %d\n", _ismbslead(s_chin, &s_chin[1]));
+
+    ok( 2 == strlen(s_chin),  "2 == strlen(s_chin), was %d\n", strlen(s_chin));
+    ok( 1 == _mbslen(s_chin), "1 == _mbslen(s_chin), was %d\n", 
_mbslen(s_chin));
+
+    ok( _MBC_LEAD  == _mbsbtype(s_chin, 0), "_MBC_LEAD  == _mbsbtype(s_chin, 
0), was %d\n", _mbsbtype(s_chin, 0) );
+    ok( _MBC_TRAIL == _mbsbtype(s_chin, 1), "_MBC_TRAIL == _mbsbtype(s_chin, 
1), was %d\n", _mbsbtype(s_chin, 1) );
+
 }

Regards,
Raphael
Index: dlls/msvcrt/mbcs.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/mbcs.c,v
retrieving revision 1.30
diff -u -r1.30 mbcs.c
--- dlls/msvcrt/mbcs.c	25 Feb 2005 14:07:57 -0000	1.30
+++ dlls/msvcrt/mbcs.c	5 Apr 2005 20:29:51 -0000
@@ -24,6 +24,7 @@
  */
 
 #include "msvcrt.h"
+#include "msvcrt/mbctype.h"
 #include "wine/unicode.h"
 #include "wine/debug.h"
 
@@ -1143,4 +1144,37 @@
         str += (MSVCRT_isleadbyte(*str)?2:1);
     }
     return NULL;
+}
+
+/*********************************************************************
+ *		_mbsbtype (MSVCRT.@)
+ */
+int _mbsbtype(const unsigned char* mbstr, size_t count) {
+  const unsigned char* str;
+  const unsigned char* start = mbstr;
+
+  str = mbstr + count;
+
+  /** from _ismbslead */
+  if (MSVCRT___mb_cur_max > 1)
+  {
+    while (start < str) {
+      if (!*start) {
+	return _MBC_ILLEGAL;
+      }
+      start += MSVCRT_isleadbyte(*str) ? 2 : 1;
+    }
+
+  }
+  if (!*str) { /** TODO: check *str validity */
+    return _MBC_ILLEGAL;
+  }
+  if (start == str && MSVCRT_isleadbyte(*str)) {
+    return _MBC_LEAD;
+  }
+  if (start == str && MSVCRT_isleadbyte(str[-1])) {
+    return _MBC_TRAIL;
+  }
+
+  return _MBC_SINGLE;
 }
Index: include/msvcrt/mbctype.h
===================================================================
RCS file: /home/wine/wine/include/msvcrt/mbctype.h,v
retrieving revision 1.5
diff -u -r1.5 mbctype.h
--- include/msvcrt/mbctype.h	25 Jun 2004 01:19:15 -0000	1.5
+++ include/msvcrt/mbctype.h	5 Apr 2005 20:29:51 -0000
@@ -27,6 +27,12 @@
 extern "C" {
 #endif
 
+/* return values for _mbsbtype  and _mbbtype */
+#define _MBC_SINGLE    0 
+#define _MBC_LEAD      1  
+#define _MBC_TRAIL     2
+#define _MBC_ILLEGAL (-1)
+
 unsigned char* __p__mbctype(void);
 #define _mbctype                   (__p__mbctype())
 

Attachment: pgp2RYmZWP1iQ.pgp
Description: PGP signature

Reply via email to