- Update _mbclen, mblen, _mbslen, _mbsnextc and _mbstrlen which should rely on the leadbyte mechanism

- Fixes 9 msvcrt string tests, 7 failures tbd
- Remove leftover function declaration from ismblead.c

svn path=/trunk/; revision=38181
This commit is contained in:
Gregor Schneider 2008-12-18 21:17:22 +00:00
parent 589af34558
commit 5fe4b4b425
5 changed files with 83 additions and 46 deletions

View file

@ -14,8 +14,6 @@
#include <precomp.h> #include <precomp.h>
#include <mbctype.h> #include <mbctype.h>
size_t _mbclen2(const unsigned int s);
/* /*
* @implemented * @implemented
*/ */

View file

@ -1,18 +1,30 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbclen.c
* PURPOSE: Determines the length of a multi byte character
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
#include <mbstring.h> #include <mbstring.h>
#include <stdlib.h> #include <stdlib.h>
int isleadbyte(int byte);
/* /*
* @implemented * @implemented
*/ */
size_t _mbclen(const unsigned char *s) size_t _mbclen(const unsigned char *s)
{ {
return (_ismbblead(*s>>8) && _ismbbtrail(*s&0x00FF)) ? 2 : 1; return _ismbblead(*s) ? 2 : 1;
} }
size_t _mbclen2(const unsigned int s) size_t _mbclen2(const unsigned int s)
{ {
return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1; return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1;
} }
/* /*
@ -20,14 +32,11 @@ size_t _mbclen2(const unsigned int s)
* *
* @implemented * @implemented
*/ */
int mblen( const char *s, size_t count ) int mblen( const char *str, size_t size )
{ {
size_t l; if (str && *str && size)
if ( s == NULL ) {
return 0; return !isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
}
l = _mbclen((const unsigned char *)s); return 0;
if ( l < count )
return -1;
return l;
} }

View file

@ -1,18 +1,32 @@
#include <mbstring.h> /*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbslen.c
* PURPOSE: Determines the length of a multi byte string
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
size_t _mbclen2(const unsigned int s); #include <mbstring.h>
/* /*
* @implemented * @implemented
*/ */
size_t _mbslen(const unsigned char *str) size_t _mbslen(const unsigned char *str)
{ {
int i = 0; size_t len = 0;
unsigned char *s; while(*str)
{
if (str == 0) if (_ismbblead(*str))
return 0; {
str++;
for (s = (unsigned char *)str; *s; s+=_mbclen2(*s),i++); if (!*str) /* count only full chars */
return i; break;
}
str++;
len++;
}
return len;
} }

View file

@ -1,20 +1,23 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbsnextc.c
* PURPOSE: Finds the next character in a string
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
#include <precomp.h> #include <precomp.h>
#include <mbstring.h> #include <mbstring.h>
/* /*
* @implemented * @implemented
*/ */
unsigned int _mbsnextc (const unsigned char *src) unsigned int _mbsnextc (const unsigned char *str)
{ {
unsigned char *char_src = (unsigned char *)src; if(_ismbblead(*str))
unsigned short *short_src = (unsigned short *)src; return *str << 8 | str[1];
return *str;
if (src == NULL)
return 0;
if (!_ismbblead(*src))
return *char_src;
else
return *short_src;
return 0;
} }

View file

@ -1,19 +1,32 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbstrlen.c
* PURPOSE: Determines the length of a multi byte string, current locale
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
#include <mbstring.h> #include <mbstring.h>
#include <stdlib.h> #include <stdlib.h>
int isleadbyte(int byte);
/* /*
* @implemented * @implemented
*/ */
size_t _mbstrlen( const char *string ) size_t _mbstrlen( const char *str )
{ {
char *s = (char *)string; size_t len = 0;
size_t i = 0; while(*str)
{
while ( *s != 0 ) { /* FIXME: According to the documentation we are supposed to test for
if ( _ismbblead(*s) ) * multi-byte character validity. Whatever that means
s++; */
s++; str += isleadbyte(*str) ? 2 : 1;
i++; len++;
} }
return i; return len;
} }