- Remove duplicate harcoded _mbctype, rename MSVCRT_mbctype to fit the new role

- Update related functions _ismbblead, _ismbslead, _ismbbtrail, _ismbstrail to use Wine _mbctype indexing
- Fixes 28 msvcrt string tests, 33 left
- Minor header updates

svn path=/trunk/; revision=38173
This commit is contained in:
Gregor Schneider 2008-12-18 18:58:43 +00:00
parent 10ffe93130
commit 1c8d9a1277
4 changed files with 47 additions and 59 deletions

View file

@ -27,7 +27,7 @@
*/ */
#define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */ #define MAX_ELEM_LEN 64 /* Max length of country/language/CP string */
unsigned char MSVCRT_mbctype[257] = { 0 }; unsigned char _mbctype[257] = { 0 };
static int g_mbcp_is_multibyte = 0; static int g_mbcp_is_multibyte = 0;
/* It seems that the data about valid trail bytes is not available from kernel32 /* It seems that the data about valid trail bytes is not available from kernel32
@ -671,13 +671,13 @@ int CDECL _setmbcp(int cp)
} }
/* setup the _mbctype */ /* setup the _mbctype */
memset(MSVCRT_mbctype, 0, sizeof(MSVCRT_mbctype)); memset(_mbctype, 0, sizeof(_mbctype));
bytes = cpi.LeadByte; bytes = cpi.LeadByte;
while (bytes[0] || bytes[1]) while (bytes[0] || bytes[1])
{ {
for (i = bytes[0]; i <= bytes[1]; i++) for (i = bytes[0]; i <= bytes[1]; i++)
MSVCRT_mbctype[i + 1] |= _M1; _mbctype[i + 1] |= _M1;
bytes += 2; bytes += 2;
} }
@ -698,7 +698,7 @@ int CDECL _setmbcp(int cp)
while (bytes[0] || bytes[1]) while (bytes[0] || bytes[1])
{ {
for (i = bytes[0]; i <= bytes[1]; i++) for (i = bytes[0]; i <= bytes[1]; i++)
MSVCRT_mbctype[i + 1] |= _M2; _mbctype[i + 1] |= _M2;
bytes += 2; bytes += 2;
} }
break; break;
@ -713,7 +713,7 @@ int CDECL _setmbcp(int cp)
*/ */
charcount = 0; charcount = 0;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
if (!(MSVCRT_mbctype[i + 1] & _M1)) if (!(_mbctype[i + 1] & _M1))
bufA[charcount++] = i; bufA[charcount++] = i;
ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount); ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
@ -724,12 +724,12 @@ int CDECL _setmbcp(int cp)
curr_type = chartypes; curr_type = chartypes;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
if (!(MSVCRT_mbctype[i + 1] & _M1)) if (!(_mbctype[i + 1] & _M1))
{ {
if ((*curr_type) & C1_UPPER) if ((*curr_type) & C1_UPPER)
MSVCRT_mbctype[i + 1] |= _SBUP; _mbctype[i + 1] |= _SBUP;
if ((*curr_type) & C1_LOWER) if ((*curr_type) & C1_LOWER)
MSVCRT_mbctype[i + 1] |= _SBLOW; _mbctype[i + 1] |= _SBLOW;
curr_type++; curr_type++;
} }
@ -741,9 +741,9 @@ int CDECL _setmbcp(int cp)
* also faster execution. * also faster execution.
*/ */
for (i = 161; i <= 165; i++) for (i = 161; i <= 165; i++)
MSVCRT_mbctype[i + 1] |= _MP; _mbctype[i + 1] |= _MP;
for (i = 166; i <= 223; i++) for (i = 166; i <= 223; i++)
MSVCRT_mbctype[i + 1] |= _MS; _mbctype[i + 1] |= _MS;
} }
MSVCRT___lc_collate_cp = MSVCRT___lc_codepage = newcp; MSVCRT___lc_collate_cp = MSVCRT___lc_codepage = newcp;

View file

@ -14,26 +14,6 @@
#include <mbstring.h> #include <mbstring.h>
#include <mbctype.h> #include <mbctype.h>
unsigned char _mbctype[257] = {
0, /* EOF */
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /* 0 */
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /* 1 */
B ,P ,P ,P ,P ,P ,P ,P ,P ,P ,P ,P ,P ,P ,P ,P , /* 2 */
D ,D ,D ,P ,D ,D ,D ,D ,D ,D ,P ,P ,P ,P ,P ,P , /* 3 */
PT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT, /* 4 */
AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,PT,PT,PT,PT,PT, /* 5 */
PT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT, /* 6 */
AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,AT,PT,PT,PT,PT,0 , /* 7 */
T ,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT, /* 8 */
LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT, /* 9 */
T ,GT,GT,GT,GT,GT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT, /* A */
KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT, /* B */
KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT, /* C */
KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,KT,GT,GT, /* D */
LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT, /* E */
LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,LT,0 ,0 ,0 , /* F */
};
/* /*
* @implemented * @implemented
*/ */

View file

@ -1,16 +1,18 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/iskana.c * FILE: lib/sdk/crt/mbstring/ismblead.c
* PURPOSE: * PURPOSE: Checks for a leading byte
* PROGRAMER: * PROGRAMERS:
* UPDATE HISTORY: * Copyright 1999 Ariadne, Taiji Yamada
* 12/04/99: Ariadne, Taiji Yamada Created * Copyright 1999 Alexandre Julliard
* 05/30/08: Samuel Serapion adapted from PROJECT C Library * Copyright 2000 Jon Griffths
* Copyright 2008 Samuel Serapion adapted from PROJECT C Library
* *
*/ */
#include <precomp.h> #include <precomp.h>
#include <mbctype.h>
size_t _mbclen2(const unsigned int s); size_t _mbclen2(const unsigned int s);
@ -19,21 +21,27 @@ size_t _mbclen2(const unsigned int s);
*/ */
int _ismbblead(unsigned int c) int _ismbblead(unsigned int c)
{ {
return (_mbctype[c & 0xff] & _MLEAD); return (_mbctype[(c&0xff) + 1] & _M1) != 0;
} }
/* /*
* @implemented * @implemented
*/ */
int _ismbslead( const unsigned char *str, const unsigned char *t) int _ismbslead( const unsigned char *start, const unsigned char *str)
{ {
unsigned char *s = (unsigned char *)str; int lead = 0;
while(*s != 0 && s != t)
{
s+= _mbclen2(*s); /* Lead bytes can also be trail bytes so we need to analyse the string
} */
return _ismbblead( *s); while (start <= str)
{
if (!*start)
return 0;
lead = !lead && _ismbblead(*start);
start++;
}
return lead ? -1 : 0;
} }
/* /*
@ -41,7 +49,7 @@ int _ismbslead( const unsigned char *str, const unsigned char *t)
*/ */
const unsigned char *__p__mbctype(void) const unsigned char *__p__mbctype(void)
{ {
return _mbctype; return _mbctype;
} }

View file

@ -1,14 +1,17 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/msvcrt/mbstring/ismbtrl.c * FILE: lib/sdk/crt/mbstring/ismbtrl.c
* PURPOSE: Checks for a trailing byte * PURPOSE: Checks for a trailing byte
* PROGRAMER: Ariadne * PROGRAMERS:
* UPDATE HISTORY: * Copyright 1999 Ariadne
* 12/04/99: Created * Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/ */
#include <precomp.h> #include <precomp.h>
#include <mbctype.h>
size_t _mbclen2(const unsigned int s); size_t _mbclen2(const unsigned int s);
@ -19,21 +22,18 @@ size_t _mbclen2(const unsigned int s);
*/ */
int _ismbbtrail(unsigned int c) int _ismbbtrail(unsigned int c)
{ {
return (_mbctype[c & 0xff] & _MTRAIL); return (_mbctype[(c&0xff) + 1] & _M2) != 0;
} }
/* /*
* @implemented * @implemented
*/ */
int _ismbstrail( const unsigned char *str, const unsigned char *t) int _ismbstrail( const unsigned char *start, const unsigned char *str)
{ {
unsigned char *s = (unsigned char *)str; /* Note: this function doesn't check _ismbbtrail */
while(*s != 0 && s != t) if ((str > start) && _ismbslead(start, str-1))
{ return -1;
else
s+= _mbclen2(*s); return 0;
}
return _ismbbtrail(*s);
} }